Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 30th, 2003, 12:39 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying Excel data in a table


Hi

I need to display a simple Excel spreadsheet as a
table within an ASP.NET webform.

Is there an easy way of doing this?

I Know I can save an Excel spreadsheet as HTML format.
But... I need to have other functionality on my webform
so I need to have the Excel spreadsheet page as a form
component - ie a table or a grid would do.

Is there a component that allows me to import Excel
data? Which I can then bind to a table or grid?

Any help or suggestions much appreciated.

Cheers
Chas from Canterbury, UK
:)



 
Old October 30th, 2003, 09:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You must highlight all cells you are going to use and name it. In the example it is named 'Dell'

Sub Page_Load(Source As Object, E As EventArgs)
  Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;" & _
                  "data source=C:\BegASPNETdb\datastores\inventory.xls;" & _
                  "Extended Properties=Excel 8.0;"
  Dim objConnection As New OleDbConnection(strConnection)

  Dim strSQL As String = "SELECT * FROM Items WHERE Source='Dell'"
  Dim objCommand As New OleDbCommand(strSQL, objConnection)

  objConnection.Open()
  dgInventory.DataSource = objCommand.ExecuteReader()
  dgInventory.DataBind()
  objConnection.Close()
End Sub

 
Old October 30th, 2003, 09:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

HTML should look like this:

<html>
<head>
    <title>Reading from an Excel Workbook</title>
</head>

<body>
    <H3>Reading from an Excel Workbook</H3>
    <asp:DataGrid id="dgInventory" runat="server" />
</body>
</html>



You will also need to import these

System.Data
System.Data.OleDb
 
Old October 4th, 2004, 05:43 AM
Authorized User
 
Join Date: Feb 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mahulda
Default

Quote:
quote:Originally posted by stu9820
 You must highlight all cells you are going to use and name it. In the example it is named 'Dell'

Sub Page_Load(Source As Object, E As EventArgs)
Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;" & _
                 "data source=C:\BegASPNETdb\datastores\inventory.xls;" & _
                 "Extended Properties=Excel 8.0;"
Dim objConnection As New OleDbConnection(strConnection)

Dim strSQL As String = "SELECT * FROM Items WHERE Source='Dell'"
Dim objCommand As New OleDbCommand(strSQL, objConnection)

objConnection.Open()
dgInventory.DataSource = objCommand.ExecuteReader()
dgInventory.DataBind()
objConnection.Close()
End Sub


Can you tell me how the Excel Sheet would be for the code you gave
This is what i used
The name of the file is Inventory.xls
Items is Cell A1 of the spreadsheet

Items Price
Item3 20
Item1 30
Item2 34


I get the following error
The Microsoft Jet database engine could not find the object 'Items'. Make sure the object exists and that you spell its name and the path name correctly.


-.. -..
 
Old October 5th, 2004, 05:00 AM
Authorized User
 
Join Date: Feb 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mahulda
Default

I have resolved my problem.

But now i have a new issue.
I run my program and display the table using a datagrid.
Now if i want to open my Excel document theres an error saying the file inventory.xls can not be opened


-.. -..
 
Old October 31st, 2005, 06:07 AM
Registered User
 
Join Date: Oct 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry guys may anyone please help me? i am trying to display the content of an excel sheet in a datagrid and i got this error

The Microsoft Jet database engine could not find the object 'myRange'. Make sure the object exists and that you spell its name and the path name correctly.


 
Old January 6th, 2006, 04:25 AM
Registered User
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mahulda, could you please tell how you resolved this problem:

The Microsoft Jet database engine could not find the object 'Items'. Make sure the object exists and that you spell its name and the path name correctly.

Thanks,
klim







Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Table data into an Excel SpreadSheet hewstone999 Access VBA 0 March 3rd, 2008 07:00 AM
Displaying DetailsView for New/Empty Data Table Sheri B ASP.NET 2.0 Basics 5 December 7th, 2006 03:08 PM
Displaying data in a table Mike707 Dreamweaver (all versions) 1 April 19th, 2006 01:43 PM
Displaying Access table data into Msflexgrid using Kaustav Pro VB Databases 0 September 25th, 2005 01:08 PM
Help displaying data in table Calibus Classic ASP Databases 3 July 2nd, 2004 08:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.