Question

Locked

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 conn.open(),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);
try
{
conn = new OleDbConnection(connectionString);
conn.Open();
}
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)

Thanks,

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Excel Repair

by ArronAd In reply to Cannot read Excel file - ...

It has to help:
Excel Repair Toolbox is powerful corrupted .XLS files repair recovery software, suitable for all instances of data corruption, including viral infections, incorrect user actions, download errors and other problems, damaging the structure of Microsoft Excel documents.

For more: https://www.xlsrepairtoolbox.com/

Back to Windows Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums