Access Excel spreadsheet 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 for your 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"/>
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 ()
' 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 for your 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.