<% @ Page Language = "C #" %>
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Data. ADO" %>
<Script language = "C #" runat = "server">
Protected void Page_Load (Object Src, EventArgs E)
{
String strConn;
StrConn = "Provider = Microsoft. Jet. OLEDB.4.0;" +
"Data Source = C: exceltest.xls;" +
"Extended Properties = Excel 8.0 ;";
'You must use the $ after the object You reference in the spreadsheet
ADODataSetCommand myCommand = new ADODataSetCommand ("SELECT * FROM [Sheet1 $]", strConn );
DataSet myDataSet = new DataSet ();
MyCommand. FillDataSet (myDataSet, "ExcelInfo ");
DataGrid1.DataSource = myDataSet. Tables ["ExcelInfo"]. DefaultView;
DataGrid1.DataBind ();
}
</Script>
<P> <asp: Label id = Label1 runat = "server"> SpreadSheet Contents: </asp: Label> </p>
<Asp: DataGrid id = maid = "server"/>
VB. NET Code
----------------------------------------------
<% @ Page Language = "VB" %>
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Data. ADO" %>
<Script language = "VB" runat = "server">
Sub Page_Load (sender As Object, e As EventArgs)
Dim myDataset As New DataSet ()
'You can also use the Excel ODBC driver I believe-didn't try though
Dim strConn As String = "Provider = Microsoft. Jet. OLEDB.4.0 ;"&_
"Data Source = C: exceltest.xls ;"&_
"Extended Properties =" "Excel 8.0 ;"""
'You must use the $ after the object You reference in the spreadsheet