Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 578
Florian Moser Avatar asked May 06 '15 13:05

Florian Moser


People also ask

How do I fix Hresult 0X800A03Ec?

Typically, Excel Error Hresult 0X800A03Ec errors are caused by a corrupt or missing Microsoft Excel-associated file, sometimes due to malware infection. File replacement is typically the best and easiest way to resolve errors related to Microsoft Corporation files.

How do I fix exceptions from Hresult 0x800ac472?

To fix it, try close the excel from Task Manager once and re-run the BoT. It should work. Per our earlier experiences, HRESULT occurs when the Excel session used has not been gracefully closed before or when multiple instances of Excel are open.


2 Answers

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

like image 135
AnalystCave.com Avatar answered Oct 10 '22 16:10

AnalystCave.com


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

like image 2
Florian Moser Avatar answered Oct 10 '22 14:10

Florian Moser