C # When reading Excel, the following error occurs: External table is not in the expected format.

Source: Internet
Author: User

In the previous log "use C # To Read Excel and return dataset", we mentioned the method of reading Excel with C #. We can find that there is no problem in reading excel2003 using this method. However, when we read excel2007, Visual Studio reports the following error: External table is not in the expected format.

In fact, this error is caused by the connection string of the Excel version,

In the method mentioned in the previous log, the Excel connection string is as follows:

Public Static String Connectionstring =@ "Provider = Microsoft. Jet. oledb.4.0; Data Source = D: \ workspace \ mydocument \ samples2.xlsx; extended properties =" "Excel 8.0; HDR = yes ;""";

When reading excel2007 using this method, you must manually open the Excel file on the current computer and place it there before runningProgramObviously, this is not our requirement.

 

To solve this problem, change the oledb and extended properties versions of the connection string as follows:

Public static string connectionstring = @ "provider = Microsoft. ace. oledb.12.0; Data Source = D: \ workspace \ mydocument \ samples.xlsx; extended properties = "" Excel 12.0; HDR = yes; "";

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.