0x800a03ec matlab,Exception HResult 0x800a03ec when trying to open Excel with Microsoft.Office.Inter...

问题

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?

回答1:

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?:

Efficiency (OpenXML is lightweight)

No memory leakage risk

Ease of use

回答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

959c56117f2297eb99c74dcefab84ddc.png

Tap on the highlighted Hyperlink

Open Advanced Settings

1b67203a07b438fa05bb82637206a036.png

Change the delimiter to a point "."

3a4573b661b1b03b768b16c546905d5b.png

回答3:

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

来源:https://stackoverflow.com/questions/30078729/exception-hresult-0x800a03ec-when-trying-to-open-excel-with-microsoft-office-int

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值