如果打开了不同的版本,为什么要获取单词实例? [英] Hw to get word instances if different versions opened?

查看:76
本文介绍了如果打开了不同的版本,为什么要获取单词实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如果运行不同版本的MS Office,如何不获取word/PPT应用程序的运行实例?
如果打开了多个版本的文档,则此代码不会返回所有的错误.
请帮忙.

Hi,
How to get no of running instances of word/PPT applications if different versions of MS office running?
This code does not return all the insatnces if multiple versions documents opened.
Please help.

//for powerpoint instance
ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
//for word instance
                        wordApp = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");

推荐答案

每个版本的COM库很可能只能访问相同版本的那些实例.因此,如果您有2个版本的Office,则可能需要分别与它们进行COM互操作.

[更新]
~~~~~~~~~~

针对您的评论:

是的,您需要链接到特定互操作版本的单独程序集.也许可以使用一个通用的程序集作为同步点.
Each version of the COM library will most likely have access to only those instances from the same version. So if you have 2 versions of Office, you''ll probably need to COM interop with them separately.

[Update]
~~~~~~~~~~

In response to your comment:

Yeah you''ll need separate assemblies that link to specific interop versions. And maybe a common assembly that can then act as the sync-ing point.


经过类似的管理,它将返回所有正在运行的进程:
Managed to somewhat like this and it will return all the running process:
Process[] wordProcs = Process.GetProcessesByName("WINWORD");
if (wordProcs.Length > 0)
{
   foreach (Process wordProc in wordProcs)
    {
      if (wordProc.MainWindowTitle != "")
        {
           //Do something here
        }
    }

}


这篇关于如果打开了不同的版本,为什么要获取单词实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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