5

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

Exception from HRESULT: 0x800A03EC

Inner Exceptions: (empty)

Stack Trace:

   at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
   at (own assembly)

This HResult is a very generic Error, I could not find any useful informations by it.

My Setup:

WCF Service running inside a Windows Service. The exact same Setup is working on three other machines.

Things I can rule out:

  • Wrong Path
  • File does not exists
  • File is corrupt
  • File is write protected

Things I've done:

  • Created the Desktop folders as seen here (second Answer) https://social.msdn.microsoft.com/Forums/vstudio/en-US/4d6c383a-94eb-4898-9d22-aa4bb69be25b/
  • Gave the Desktop Folders "Everyone" or "Jeder" Permissions ("Jeder" is the equivalent of "Everyone" in German)
  • Started the Service with the currenlty active User
  • Changed the DCOM Config for Excel as advised by Heidi2 (see Link above)
  • Changed from Office 365 to Office Professional Plus
  • Locale is set to en-US while trying to open the file
  • Opened file manually which is supposed to be opened: no errors / warnings / user dialogs from excel
  • Installed English - US on target machine
  • Wrote an non WCF Service which starts the dll which executes the Interop request
  • Wrote an Console Application which starts the dll which executes the Interop request

Some Observations:

  • If I remove the Desktop folders (see my first "Things I've done"), I get the error as described and resolved here: Microsoft Office Excel cannot access the file 'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx'
  • Excel is open for a short time in the task manager while the dll tries to open the excel file
  • while I've had Office 365 installed, Office Click-Once Tasks opped up in Task Manager, sometimes freezing the Application. That's why I've switched to Professional Plus
  • If the active language is set to English US, this error is not thrown anymore; but images, which are supposed to be rendered by Interop, are rendered blank

What am I missing here?

Florian Moser
  • 2,583
  • 1
  • 30
  • 40

3 Answers3

4

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

AnalystCave.com
  • 4,884
  • 2
  • 22
  • 30
  • Yeah you are right. Unfortunately, I am not the writer of the library which makes the call to Interop, and therefore cannot change it. As far as I've understood, the lib already uses the OpenXML library to change values etc, but in the end, it needs to take a screenshot of the generated file. For this specific action, it uses Interop. – Florian Moser May 06 '15 at 15:52
2

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 "."

Florian Moser
  • 2,583
  • 1
  • 30
  • 40
0

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);
KDWolf
  • 398
  • 2
  • 14