Access Excel workbooks in ASP. NET

Source: Internet
Author: User

<% @ 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 = maid = "server"/>
VB. NET Code
----------------------------------------------
<% @ Page Language = "VB" %>
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Data. ADO" %>
<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't try though
Dim strConn As String = "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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.