自动化 Microsoft Word 时的 RPC_E_SERVERFAULT

发布于 2024-07-17 06:01:24 字数 415 浏览 2 评论 0原文

我正在通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘦怹 2024-07-24 06:01:24

您可能会讨厌我并可能对我投反对票,但在我使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文