.net 应用程序中的 interop.word 问题

发布于 2024-11-15 03:49:06 字数 571 浏览 2 评论 0原文

解决方案环境:

MS Visual Studio 2010 Ultimate、MS Office 2010 Professional、Microsoft Interop 类

场景:

我创建了一个 .Net 应用程序,它使用 Interop 类与 MS Word 进行交互。考虑一下:一个模仿键值对表的应用程序。当用户单击“值”字段时,.net 应用程序将打开一个 winword 窗口,用户可以在其中输入一些注释。单击关闭 (winword) 后,.net 应用程序将执行 winword.wordopenxml 并将数据保存在字段中。为此,我向 winword 添加了事件句柄。该应用程序运行得非常好。当我打开多个 winword 实例(由用户单独打开,但不通过 .net 应用程序)时,就会出现问题。 .net 应用程序中的事件处理程序适用于 winword 的所有实例,因此,在仅关闭一个实例单词时,所有其他实例也会关闭。我尝试了不同的方法来初始化应用程序中的单词对象。我还尝试了“初始化 winword 的两个实例并退出第一个实例”的工作 ->这种方法也效果不佳。

大师:您能帮我找到一个合适的解决方案来解决这个问题吗?

-鲁佩什

Solution Environment:

MS Visual Studio 2010 Ultimate, MS Office 2010 Professional, Microsoft Interop classes

Scenario:

I've created a .Net application which uses the Interop classes to interact with MS Word. Consider this: An application which mimics a key-value pair table. When the user clicks on the "value" field, the .net application opens up a winword window where the user can enter some notes. Upon clicking close (winword), .net app will do a winword.wordopenxml and save the data in the field. For this to happen, i've added event handles to winword. The application runs perfectly fine. The problem arises when i have multiple instances of winword opened (separately by the user but not thru the .net application) . The event handlers from the .net application is applied to all instances of winword and hence, upon closing just one instance word, all the other instances gets closed too. I tried different ways to initialize the word object in the application. I also tried the work around "Initializing two instances of winword and quit the first instance" -> This approach also did not work well.

Gurus: Could you please help me find a suitable solution for this problem ?

-Rupesh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

森林迷了鹿 2024-11-22 03:49:06

这并不是真正发生的事情。您可能看起来有多个正在运行的 Word 实例,但实际上只有一个实例。 Word 是一个非常大的程序,需要大量的系统资源。当用户启动另一个副本时,该副本会检查 Word 是否已在运行并要求它打开该文档。然后退出。原始实例只是创建另一个窗口,否则它看起来确实与 Word 的另一个实例完全相同。

因此,当您退出 Word 时,您也会杀死所有其他窗口。使用Taskmgr.exe、“进程”选项卡来验证这一点。作为解决方法,请考虑枚举 Documents 集合以查看还打开了哪些内容。

This is not what is really going on. It may look like you have multiple instances of Word running but there really is only one. Word is a very large program that requires a lot of system resources. When the user starts another copy, that copy checks if Word is already running and asks it to open the document. And quits. The original instance just creates another window, it otherwise indeed looks exactly like another instance of Word.

So when you make Word exit, you kill all the other windows as well. Use Taskmgr.exe, Processes tab to verify this. As a workaround, consider enumerating the Documents collection to see what else is opened.

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