Excel “External table is not in the expected format.”

后端 未结 24 2016
执念已碎
执念已碎 2020-11-22 05:13

I\'m trying to read an Excel (xlsx) file using the code shown below. I get an \"External table is not in the expected format.\" error unless I have the file already open in

24条回答
  •  独厮守ぢ
    2020-11-22 05:20

    Thanks for this code :) I really appreciate it. Works for me.

    public static string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
    

    So if you have diff version of Excel file, get the file name, if its extension is .xlsx, use this:

    Private Const connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
    

    and if it is .xls, use:

    Private Const connstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" + path + ";Extended Properties=""Excel 8.0;HDR=YES;"""
    

提交回复
热议问题