<%@ 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=DataGrid1 runat="server"/>
asp.net访问excel
最新推荐文章于 2022-06-13 16:49:03 发布