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

后端 未结 24 1542
执念已碎
执念已碎 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:36

    I had the same problem. which as resolved using these steps:

    1.) Click File

    2.) Select "save as"

    3.) Click on drop down (Save as type)

    4.) Select Excel 97-2003 Workbook

    5.) Click on Save button

    0 讨论(0)
  • 2020-11-22 05:37

    That excel file address may have an incorrect extension. You can change the extension from xls to xlsx or vice versa and try again.

    0 讨论(0)
  • 2020-11-22 05:38

    "External table is not in the expected format." typically occurs when trying to use an Excel 2007 file with a connection string that uses: Microsoft.Jet.OLEDB.4.0 and Extended Properties=Excel 8.0

    Using the following connection string seems to fix most problems.

    public static string path = @"C:\src\RedirectApplication\RedirectApplication\301s.xlsx";
    public static string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
    
    0 讨论(0)
  • 2020-11-22 05:38

    Just add my case. My xls file was created by a data export function from a website, the file extention is xls, it can be normally opened by MS Excel 2003. But both Microsoft.Jet.OLEDB.4.0 and Microsoft.ACE.OLEDB.12.0 got an "External table is not in the expected format" exception.

    Finally, the problem is, just as the exception said, "it's not in the expected format". Though it's extention name is xls, but when I open it with a text editor, it is actually a well-formed html file, all data are in a <table>, each <tr> is a row and each <td> is a cell. Then I think I can parse it in a html way.

    0 讨论(0)
  • 2020-11-22 05:40

    I was getting errors with third party and Oledb reading of a XLSX workbook. The issue appears to be a hidden worksheet that causes a error. Unhiding the worksheet enabled the workbook to import.

    0 讨论(0)
  • 2020-11-22 05:41

    ACE has Superceded JET

    Ace Supports all Previous versions of Office

    This Code works well!

            OleDbConnection MyConnection;
            DataSet DtSet;
            OleDbDataAdapter MyCommand;
            
            MyConnection = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\\Book.xlsx;Extended Properties=Excel 12.0;");
            MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
            DtSet = new System.Data.DataSet();
            
            MyCommand.Fill(DtSet);
            dataGridView1.DataSource = DtSet.Tables[0];
            MyConnection.Close();
    
    0 讨论(0)
提交回复
热议问题