Exception HResult 0x800a03ec when trying to open Excel with Microsoft.Office.Interop.Excel.Workbooks.Open()

前端 未结 3 1246
轻奢々
轻奢々 2021-01-06 01:44

Following Exception is thrown if I try to open an excel file on a client machine:

Exception from HRESULT: 0x800A03EC

Inner Exceptions: (emp

相关标签:
3条回答
  • Sorry - I know this is an indirect answer, although I would recommend you follow on. I personally have very bad experiences with Excel Interop services (ASP.NET application). As I am aware Microsoft does not recommend Interop server automation.

    Even if you solve this issue you might stumble into issues with memory leakage, performance etc. In my previous project we were advanced with Excel interop automation until deployment. We stumbled into so many issues (Excel Interop processes not closing properly etc.) that we had to rewrite everything to OpenXML.

    If possible use the new OpenXML format. There is a ClosedXML library that makes working with very easy.

    Why OpenXML vs Interop?:

    1. Efficiency (OpenXML is lightweight)

    2. No memory leakage risk

    3. Ease of use

    0 讨论(0)
  • 2021-01-06 02:29

    We have converted our Client / Server solution from 4GL language to C#, where embedded C# code below worked without any issue before, and started to receive same error message.

    Excel.Application excelApp = new Excel.Application();
    Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(fileExcel,
        0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
        true, false, 0, true, false, false);
    

    I have followed all the instructions in this thread, but to no avail, until I have realised that in our case at least fileExcel, which contains the full path with the name of the file and defined as System.String fileExcel had trailing spaces, e.g. instead of "C:\temp\MyTest.xls" it was "C:\temp\MyTest.xls[many many spaces]". Once I have added Trim() to fileExcel as below, all went back to normal. Hope it will help to someone in the future.

    Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(fileExcel.Trim(),
        0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
        true, false, 0, true, false, false);
    
    0 讨论(0)
  • 2021-01-06 02:34

    Before trying this solution be sure that you read the "Things I've done" paragraph from the question (and tried what applies to you)

    The Exception was thrown upon opening the Document; on the machine which generated the Excels, the files were generated invalid.

    The solution was to change the Format of the numbers.

    Go into System Configuration -> Time, Language and Region -> Language

    Go into Systemconfiguration -> Time, Language and Region -> Language

    Tap on the highlighted Hyperlink

    Open Advanced Settings

    Open Advanced Settings

    Change the delimiter to a point "." Change the delimiter to a point "."

    0 讨论(0)
提交回复
热议问题