How can I start MS Office Word from .NET without Add-ins?

怎甘沉沦 提交于 2019-12-06 02:46:33

问题


I'm using MS Office 2003 PIA to create a MS Word document from c#.

ApplicationClass officeApplication = new ApplicationClass();

Is there any way to specify that I don't want any office add-ins to be loaded using this method?

EDIT:

I know that one can do this via command line so I'm pretty sure there must be a way to do it from code:

"C:\Program Files\Microsoft Office\Office11\Winword.exe" /a  

回答1:


This code unload the AddIns

officeApplication.AddIns.Unload(false);

Edited:

When you need to mix the process start and possibility to use the office "application" interface, you need the Marshal.GetActiveObject command.
Example :

        //startup without plugins
        System.Diagnostics.Process.Start(
            @"Winword.exe",
            @"/a");
        //give a time for startup
        Thread.Sleep(2000);
        //attach to office
        Application officeApplication = (Application)Marshal.GetActiveObject("Word.Application");



回答2:


Try this

System.Diagnostics.Process.Start(
  @"C:\Program Files\Microsoft Office\Office11\Winword.exe", 
  @"/a");


来源:https://stackoverflow.com/questions/608152/how-can-i-start-ms-office-word-from-net-without-add-ins

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!