Cannot read Excel file - External table is not in the expected format

By greerjohn ·
Tags: Windows, Software
I am trying to open/read this attached (Excel 2003) test.xls file using oledb in c#, but when the code gets to,the exception "External table is not in the expected format" occurs. (This test.xls file only has one empty sheet called Test. (no macros or vba code in the xls)
(I can open the file file from within Excel 2003)

public OleDbConnection openExcelConnection(string fullpath, string bHeader, out string errorMessage)
errorMessage = "";
string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'", fullpath, bHeader);

OleDbConnection conn;
conn = new OleDbConnection(connectionString);
conn = new OleDbConnection(connectionString);
catch (Exception e)
errorMessage = e.Message;
return conn;
} //openExcelConnection()

I am not sure what is going on here. Is this a corrupted xls file? (I tried the Excel repair utility on the Excel File/Open screen - It doesn't say if it was repaired or not). I've tried different connection strings I read off various sites with no luck. Can anyone out there read this file successfully using oledb or any other way in c#?

This xls file originally had about 20 tabbed worksheets on it which I removed trying to narrow down the problem.

Also, If I copy this test sheet to a different workbook that the c# could read, then that workbook stops working with that error, even if I then remove the bad sheet again. The new workbook becomes tainted.

(I have another 100-150 xls files (All Excel 2003 xls files) that open fine from my C# program. Just this one is the problem.) (I am using Visual Studio 2008 .Net Framework 3.5.1)


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Related Discussions

Related Forums