Excel Interop Workbooks.Open inconsistencies

偶尔善良 提交于 2020-01-07 03:50:22

问题


I have a process that is opening multiple workbooks

var exApp = new Excel.Application(); 
Excel.Workbook ONE;
Excel.Workbook TWO;
Excel.Workbook THREE;
ONE = exApp.Workbooks.Open(ONELocation);
TWO = exApp.Workbooks.Open(TWOLocation);
THREE = exApp.Workbooks.Open(THREELocation);
Console.WriteLine("All Excel workbooks opened successfully\n");

Sometimes it runs with no issues.

Sometimes though I get the following exception on crash

System.Runtime.InteropServices.COMException: 'The remote procedure call failed. (Exception from HRESULT: 0x800706BE)'

The exception happens on different workbooks and sometimes not at all. When it happens after rerunning a few times the process goes through successfully and all data is processed correctly.

Why does it work sometimes and not others? Is there a better way to open these workbooks? How do I stop this from happening?


回答1:


RPC_S_CALL_FAILED was indeed the root cause as pointed out by the question user xxbbcc linked to as a possible duplicate.

However, that just told me the cause and did not solve the problem. I googled RPC_S_CALL_FAILED with the word excel and found this SuperUser question

I disabled the "FoxitReader PDF Creator COM Add-in" as described in the question and my program now runs consistently without error.

How to disable the plugin: Excel > File > Options > Add-ins > Manage, then choose "COM add-ins" > Go. And then untick the problematic plugin.



来源:https://stackoverflow.com/questions/44639150/excel-interop-workbooks-open-inconsistencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!