C# Code
<%@ Page Language=C# %> <%@ Import Namespace=SystemData %> <%@ Import Namespace=SystemDataADO %> <script language=C# runat=server> protected void Page_Load(Object Src EventArgs E)
{ string strConnstrConn = Provider=MicrosoftJetOLEDB +Data Source=C\\exceltestxls +Extended Properties=Excel ADODataSetCommand myCommand = new ADODataSetCommand(SELECT * FROM [Sheet$] strConn)DataSet myDataSet = new DataSet()myCommandFillDataSet(myDataSet ExcelInfo)DataGridDataSource = myDataSetTables[ExcelInfo]DefaultViewDataGridDataBind()} </script> <p><aspLabel id=Label runat=server>Excel表格內容</aspLabel></p> <aspDataGrid id=DataGrid runat=server/>
VBNET Code
<%@ Page Language=VB %> <%@ Import Namespace=SystemData %> <%@ Import Namespace=SystemDataADO %> <script language=VB runat=server> Sub Page_Load(sender As Object e As EventArgs)
Dim myDataset As New DataSet()
Dim strConn As String = Provider=MicrosoftJetOLEDB _ & Data Source=C\exceltestxls _ & Extended Properties=Excel Dim myADODataSetCommand As New ADODataSetCommand(SELECT * FROM [Sheet$] strConn)
myADODataSetCommandTableMappingsAdd(Table ExcelTest)
myADODataSetCommandFillDataSet(myDataset)
DataGridDataSource = myDatasetTables()DefaultView DataGridDataBind()
End Sub </script> <p><aspLabel id=Label runat=server>Excel表格內容</aspLabel></p> <aspDataGrid id=DataGrid runat=server/>
From:http://tw.wingwit.com/Article/program/net/201311/11439.html