asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

在ASP.NET访问Excel文件 (VB and C#)


发布日期:2020年03月07日
 
在ASP.NET访问Excel文件 (VB and C#)

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 ExcelInfoDataGridDataSource = 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/>

               

上一篇:ASP.NET实现页面间值传递的几种方法介绍

下一篇:ASP.NET中TreeView控件使用小结