Excel import error: The External table format is not the expected Solution

Source: Internet
Author: User

If you have any questions, add the QQ group.14670545Discussion

After exporting the Excel file on the Asp.net website, import the file to the database. An error occurred while reading the Excel file.

Error: The External table is not in the expected format.

An error occurred while opening the link in conn. open.

After carefully reading the link string, check whether an error occurs. If the Excel version is incorrect, the exce connection string version is office2003. If it is changed to excel2007, the data is imported normally.

The summary rules are as follows:

Using system. data. oledb; using system. data; Public void readexcelfiless (string excelpath) {// string strconn = "provider = Microsoft. jet. oledb.4.0; "+" Data Source = "+ excelpathexcelname. replace (@ "\", "\") + "; extended properties = 'excel 8.0; HDR = yes; IMEX = 1'"; // This connection can only operate on the top of excel2007(.xls) file string strconn = "provider = Microsoft. ace. oledb.12.0; "+" Data Source = "+ server. mappath ("excelfiles/mydata2007.x LSX ") +"; extended properties = 'excel 12.0; HDR = yes; IMEX = 1' "; // This connection can operate the. xlsand. XLSX files (supports the connection strings of excel2003 and excel2007) // note: "HDR = yes;" indicates that the first row of an Excel file is a column name rather than data. "HDR = no;" is the opposite of the previous one. // "IMEX = 1" if the data types in the column are inconsistent, use "IMEX = 1" to avoid data type conflicts. Oledbconnection conn = new oledbconnection (strconn); oledbdataadapter ADP = new oledbdataadapter ("select * from [sheet1 $]", Conn); dataset DS = new dataset (); ADP. fill (DS, "book1"); this. gridview1.datasource = Ds. tables ["book1"]. defaultview; this. gridview1.databind ();}

Of course, this processing method is always not safe, and the group number is constructed using office, Excel. dll.

Http://www.codeproject.com/Articles/8500/Reading-and-Writing-Excel-using-OLEDB

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.