Excel Interop工作簿.打开不一致 [英] Excel Interop Workbooks.Open inconsistencies
问题描述
我有一个正在打开多个工作簿的过程
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:'远程过程调用失败. (来自HRESULT的异常:0x800706BE)'
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?
推荐答案
RPC_S_CALL_FAILED
确实是根本原因. -interopservices-comexception-0x800706be-when-getting-contact-la>问题用户xxbbcc链接为可能的重复项.
RPC_S_CALL_FAILED
was indeed the root cause as pointed out by the question user xxbbcc linked to as a possible duplicate.
但是,这只是告诉了我原因,而没有解决问题.
我用excel字词搜索了RPC_S_CALL_FAILED
,发现了这个超级用户问题
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
我按照问题中的说明禁用了"FoxitReader PDF Creator COM加载项" ,并且我的程序现在始终运行且没有错误.
I disabled the "FoxitReader PDF Creator COM Add-in" as described in the question and my program now runs consistently without error.
如何禁用插件:Excel>文件>选项>加载项>管理,然后选择"COM加载项">转到.然后取消选中有问题的插件.
How to disable the plugin: Excel > File > Options > Add-ins > Manage, then choose "COM add-ins" > Go. And then untick the problematic plugin.
这篇关于Excel Interop工作簿.打开不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!