创建专属单词实例
我正在使用 ac# .net4 winforms 应用程序创建一个具有互操作性的 word (14) 实例来处理文档。如果某些 Word 文档在我的应用程序之外打开,则会使用相同的 Word 实例,从而干扰我的应用程序。
简单问题:有什么方法可以将我的单词实例设置为我的应用程序专用?
提前致谢。
顺便说一句:发现了一些带有 Exclusive/word/office/isolated/block/instance 的东西,但无论如何都没有答案。
i am creating a word (14) instance with interop out of a c# .net4 winforms application to work with a document. If some word document gets opened beyond my application the same word instance will be used an disturbs my application.
Simple question: Is there any way to set my word instance exclusive for my application?
Thanks in advance.
Btw: Found some stuff with exclusive/word/office/isolated/block/instance but no answers anyhow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一种解决方案,但它并不漂亮。
主要问题是Word 将自身注册到ROT(运行对象表)中,然后其他应用程序可以轻松访问在ROT 中注册的Word 实例(这就是VB GetObject 函数的作用)。
因此,在您的应用程序中,您基本上必须做两件事
即使您终止第一个实例,它也不会“追溯”在 ROT 中注册自身,并且其他应用程序通常不会反对使用对其的引用,它们会自动创建一个新实例,因为没有其他实例不再在 ROT 中注册,然后将被注册。
也就是说,其他应用程序仍然有可能获取您的 Word 实例,因此这种技术并非万无一失。如何?因为 Word 还将每个加载的文档注册到 ROT 中。但这是一个很少使用的功能。
There's sort of a solution, but it's not pretty.
The main issue is that Word registers itself in the ROT (Running Object Table), and other applications can then easily get access to the instance of Word registered in the ROT (that's what the VB GetObject function does for instance).
So, in your app, you'd basically have to do 2 things
Even though you terminate that first instance, It won't "retroactively" register itself in the ROT, and other applications will generally not object a reference to it to use, they'll automatically create a new instance, which, since no other instance is registered in the ROT anymore, will then get registered.
That said, it is still possible for other apps to get at your instance of Word, so this technique isn't bulletproof. How? Because Word ALSO registers each loaded DOCUMENT in the ROT. But that's a pretty seldom used feature.
不,您无法仅为自己锁定 Word 实例。
但是,根据您的评论,解决该问题很容易 - 不要使用
ActiveDocument
。您可以通过调用特定的文档,然后使用该变量(无论您是打开现有文档还是创建新文档)来绕过使用 ActiveDocument。例如:
在上述两种情况下,您只需使用
d
代替以前使用的ActiveDocument
。No, there is no way for you to lock an instance of Word just for yourself.
But, based on your comment, it's easy to work around the issue - don't use
ActiveDocument
. You can get around usingActiveDocument
by calling the document something specific and then using that variable (whether you are opening an existing doc or creating a new one).For example:
In both cases above, you'd just use
d
in place of where you used to useActiveDocument
.