自动化 Microsoft Word 时的 RPC_E_SERVERFAULT
我正在通过 Microsoft.Office.Interop.Word
从模板 (.dot) 创建 Word 文档。 下面的代码适用于某些模板,但不适用于其他模板:如果它不起作用,则会抛出 RPC_E_SERVERFAULT
异常。 这是怎么回事,可能是什么原因,我该如何解决? (异常发生在第二行。)
wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
wordDoc = wordApp.Documents.Add(ref oTemplate, ref newTemplate, ref docType, ref isVisible);
wordApp.Visible = false;
wordDoc.Activate();
I'm creating word documents from templates (.dot) via Microsoft.Office.Interop.Word
. The code below works on some templates but not on others: where it doesn't work it throws an RPC_E_SERVERFAULT
exception. What is this about, what can be the cause, and how could I fix it? (The exception occurs on the second line.)
wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
wordDoc = wordApp.Documents.Add(ref oTemplate, ref newTemplate, ref docType, ref isVisible);
wordApp.Visible = false;
wordDoc.Activate();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会讨厌我并可能对我投反对票,但在我使用 COM Interop 的所有 .NET 工作经验中,都是 PIA(双关语/PIA 也意味着主互操作程序集)。
通常情况下,表现非常糟糕,以至于整个事情都无法接受。 因此,我们求助于购买第 3 方、托管、不依赖 Office 的库,该库可以更快地完成相同的操作。
You will hate me and downvote me probably but in all my .NET work experience working with the COM Interop is a PIA (pun intended / PIA also means Primary Interop Assemblies).
Usually the performance is so bad that makes the whole thing unacceptable. So we resorted to buying a 3rd party, managed, non-Office-dependent library that does the same thing WAY faster.