“呼叫被呼叫者拒绝"的奇怪行为. Excel的例外 [英] Strange behaviour of "Call was rejected by callee." exception with Excel

查看:183
本文介绍了“呼叫被呼叫者拒绝"的奇怪行为. Excel的例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含将数据导出到Excel的应用程序.而且它在大多数计算机上都可以正常工作.但是,有两个会抛出

I have an application that includes data exporting to Excel. And it works fine on most computers. However, there're two that throw

呼叫被呼叫者拒绝. (来自HRESULT的异常:0x80010001(RPC_E_CALL_REJECTED))

Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))

当我尝试使用get_item()打开工作表时.有趣的是,当我设置断点并逐个字符串地执行所有操作时,没有任何异常.一切正常且流畅.但是在正常的工作行为中,它只是给出了例外.

when I try to open Worksheet with get_item(). The funny thing is, when I set up breakpoints and execute everything string by string there are no exceptions whatsoever. Everything works fine and smooth. But in normal working behaviour, it just gives this exception.

MyApp = new Excel.Application();
MyApp.Visible = false;
string FileFullPath = Path.GetFullPath("Resources/Excel/FullMonthlyAct.xls");
MyBook = MyApp.Workbooks.Open(FileFullPath);
MySheet = (Excel.Worksheet)MyBook.Worksheets.get_Item(1); 
Excel.Range excelCell = MySheet.Cells[1, 1] as Excel.Range;

更新: 它不是上述问题的重复.在那里,大多数答案告诉您检查Office激活/安装/文件关联.正如我在 Hans Passant 的帮助下发现的那样,我收到此错误的原因仅仅是因为Excel无法及时加载工作簿.

UPDATE: It's not a duplicate of the mentioned questions. There, most of the answers tell to check Office activation/installation/file assosiation. And as I've found out with the help of Hans Passant, i get this error simply because Excel can't load the workbook in time.

更新:已解决 可能不是最优雅的解决方案,但是可以等到Excel打开工作簿,如 https://stackoverflow.com/a中所述/54126361/1442373 通过 Joost .

UPDATE: Solved Not the most elegant solution maybe, but it's possible to just wait till Excel opens the workbook as described in https://stackoverflow.com/a/54126361/1442373 by Joost.

推荐答案

您的应用程序将在安装了excel并正确激活的所有计算机上运行.由于这些机器可能未正确激活Microsoft excel,因此无法在这些机器上工作.您需要确保它能够解决问题.

Your applicaton will work on all machines that have excel installed and properly activated. It is not working on those machines because they might not have activated microsoft excel properly. You need to make sure it and the problem will be resolved.

这篇关于“呼叫被呼叫者拒绝"的奇怪行为. Excel的例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆