Search code examples
excelwcfwindows-servicesinterop

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


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?


Solution

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