Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception while opening an Excel file

I have an Excel file which gives error while opening it manually:

excel found unreadable content in *****.xlsx. Do you want to recover the content of this workbook? If you trust this workbook click yes.

If I click yes, I can open it in usual way, but if I use:

Excel.Application oExcelApp;
Excel.Workbook excelWorkbook = oExcelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

I am getting a COMException:

Exception from HRESULT: 0x800A03EC

How to handle this exception. How can I make it open or show that error which is shown everytime I open it manually.

I am using MS Office 2010.

like image 421
shriguru nayak Avatar asked Nov 12 '22 07:11

shriguru nayak


1 Answers

Try to change your 4th parameter type to XlFileFormat (enumeration) and choose the a fitting value (enum description). Maybe 5 (xlWK1 value in enum) is the wrong one...

for example

Excel.Application oExcelApp;
Excel.Workbook excelWorkbook = oExcelApp.Workbooks.Open(workbookPath, 0, false, Excel.XlFileFormat.xlWorkbookDefault, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
like image 148
tobias-kutter Avatar answered Nov 15 '22 07:11

tobias-kutter