访问 电子表格,访问 电子表格
C# Code
---------------------------------------------
<%@ Page Language="C#" %
<%@ Import Namespace="&; %
<%@ Import Namespace="&; %
<script language="C#" runat="server"
protected void Page_Load(Object Src, EventArgs E)
{
string strConn;
strConn = "Provider=&; +
"Data Source=C:\&; +
"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();
(myDataSet, "ExcelInfo");
= &&;
();
}
</script
<p< id=Label1 runat="server"SpreadSheet Contents:</</p
< id=DataGrid1 runat="server"/
Code
----------------------------------------------
<%@ Page Language="VB" %
<%@ Import Namespace="&; %
<%@ Import Namespace="&; %
<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 try though
Dim strConn As String = "Provider=&; & _
"Data Source=C:&; & _
"Extended Properties=""Excel 8.0;"""
You must use the $ after the object you reference in the spreadsheet
Dim myADODataSetCommand As New ADODataSetCommand("SELECT* FROM [Sheet1$]", strConn)
myADODataSetCommand.TableMappings.Add("Table", "ExcelTest")
myADODataSetCommand.FillDataSet(myDataset)
= myDataset.Tables(0).DefaultView
()
End Sub
</script
<p< id=Label1 runat="server"SpreadSheet Contents:</</p
< id=DataGrid1 runat="server"/