ASP. NET reads Excel content and displays it on the Web. asp. netexcel

Source: Internet
Author: User

ASP. NET reads Excel content and displays it on the Web. asp. netexcel

The example in this article describes how ASP. NET can read Excel content and display it on the Web. It is a very practical function and can be shared with you for your reference. The specific implementation method is as follows:

Click the Event code. cs Code as follows:

protected void Button1_Click(object sender, EventArgs e){    string strPath = "d:/test.xls";    string mystring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = '" + strPath + "';Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";      //"Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + strPath + "';Extended Properties=Excel 8.0";    OleDbConnection cnnxls = new OleDbConnection(mystring);    OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [Sheet1$]", cnnxls);    DataSet myDs = new DataSet();    myDa.Fill(myDs);    DataGrid1.DataSource = myDs.Tables[0];    DataGrid1.DataBind(); }

Note:

If you use the classic "Provider = Microsoft. Jet. OLEDB.4.0; Data Source = '" + strPath + "'; Extended Properties = Excel 8.0", an error is returned: The External table is not in the expected format.

This is because: Microsoft. jet. OLEDB.4.0 is the Microsoft Jet Engine, which is applicable to version 2003 (which has not been tested before version 2003, so I do not know which version can be adapted to). In version 2007, microsoft modified its Access and Excel file formats and renamed them. accdb (Access 2007 database file) and. xlsx (Excel 2007 file) is not supported by the Microsoft Jet Engine, but Microsoft quickly proposed Microsoft Office 2007 Desktop Drivers: Data Connectivity Components.

Therefore, the solution is to change the data provider in the connection string to Microsoft. ACE. OLEDB.12.0.


Aspnet web reads images through excel, and can obtain the path of the image and the cell in which the image is located?

An image in Excel does not belong to a cell. In addition, an image is stored in an EXCEL file as a binary information. How do I obtain the path? There is no path at all

Use asp, php, or html to read excel Data and display it on the current webpage.

Use an excel file as a data source. For example, when using the oledb connection method, a worksheet is equivalent to a table data table and can be read cyclically.

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.