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; "";