简体   繁体   English

打开Excel文件时出现异常

[英]Exception while opening an Excel file

I have an Excel file which gives error while opening it manually: 我有一个Excel文件,在手动打开时会出错:

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: 我收到一个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. 我正在使用MS Office 2010。

Try to change your 4th parameter type to XlFileFormat (enumeration) and choose the a fitting value ( enum description ). 尝试将第4个参数类型更改为XlFileFormat(枚举)并选择拟合值( 枚举描述 )。 Maybe 5 ( xlWK1 value in enum) is the wrong one... 也许5(枚举中的xlWK1值)是错误的...

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM