.net应用程序中的interop.word问题 [英] Problem with interop.word in a .net application

查看:82
本文介绍了.net应用程序中的interop.word问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案环境:

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

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

场景:

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

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

推荐答案

这不是真正的情况.看起来您有多个运行的Word实例,但实际上只有一个. Word是一个非常大的程序,需要大量的系统资源.当用户启动另一个副本时,该副本将检查Word是否已在运行,并要求它打开文档.并退出.原始实例只是创建了另一个窗口,否则它的确确实看起来像Word的另一个实例.

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.

因此,当您退出Word时,也会杀死所有其他窗口.使用Taskmgr.exe的进程"选项卡进行验证.作为解决方法,请考虑枚举Documents集合以查看还有哪些打开的对象.

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.

这篇关于.net应用程序中的interop.word问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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