熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

在ASP.NET訪問Excel文件 (VB and C#)

2013-11-13 09:44:01  來源: .NET編程 

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


From:http://tw.wingwit.com/Article/program/net/201311/11439.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.