简体   繁体   English

在机器中分离 Microsoft.Office.Interop.Word 实例和 Word 应用程序

[英]Separate Microsoft.Office.Interop.Word instance and Word app in machine

in my application i want to use microsoft word using在我的应用程序中,我想使用 microsoft word

Microsoft.Office.Interop.Word Microsoft.Office.Interop.Word

Microsoft.Office.Interop.Word.Application _wordApplication
= new Microsoft.Office.Interop.Word.Application();
this._wordApplication.Documents.Add();

object _readOnly;
    object _addToRecentFiles;
    object _confirmConversion;
    object _trueValue;
    object _falseValue;
    object _visible;
    object _nullObj;
object fileName = @"C:/FileName.doc";

var doc = _wordApplication.Documents.Open(ref fileName, ref _confirmConversion, ref _readOnly, ref _addToRecentFiles,
                    _oMissing, _oMissing, _oMissing, _oMissing, _oMissing, _oMissing, _oMissing, _visible, _oMissing,
                    _oMissing, _oMissing, _oMissing);

i want to separate between word application on my machine and word in my solution because if i modify the word application on machine with the following steps我想在我的机器上的 word 应用程序和我的解决方案中的 word 之间分开,因为如果我使用以下步骤修改机器上的 word 应用程序

View > Read Mode查看 > 阅读模式

and close the word application then i open the word in my solution >> the word will open in并关闭单词应用程序然后我在我的解决方案中打开单词 >> 该单词将在

Read Mode not Print layout mode阅读模式不是打印布局模式

So my question is how to separate between Word application and word instance in my solution i want any change in my solution do not effect in microsoft office word in my machine and vice versa所以我的问题是如何在我的解决方案中分离 Word 应用程序和 word 实例我希望我的解决方案中的任何更改都不会影响我机器中的 microsoft office word,反之亦然

Due to how Word stores many of the settings values in the Registry (and others in the Normal.dotm template), under a single user profile key, it's not possible to choose or change what the Word application saves when it exits, whether the settings changes were made by a user or by code.由于 Word 在注册表中存储许多设置值(以及Normal.dotm模板中的其他设置值),在单个用户配置文件项下,无法选择或更改 Word 应用程序退出时保存的内容,无论设置是更改是由用户或代码进行的。 This behavior is by design and cannot be configured differently.此行为是设计使然,不能以不同方式进行配置。

The only way to keep a completely separate environment would be to run the "interop" version under a different user profile.保持完全独立的环境的唯一方法是在不同的用户配置文件下运行“互操作”版本。

Barring that, to ensure that the "interop" environment runs with different settings from the end-user environment, the "interop" code needs take note of each setting of concern when it starts, change those settings to the ones required for itself and, when it ends, reset to the settings saved when the "interop" started.除此之外,为了确保“互操作”环境以与最终用户环境不同的设置运行,“互操作”代码在启动时需要注意每个关注的设置,将这些设置更改为自身所需的设置,并且,当它结束时,重置为“互操作”开始时保存的设置。

There would be the possibility of starting a Word process in "Safe Mode", which would run Word using the installation defaults, but that would still mean creating settings when the instance starts.有可能在“安全模式”下启动 Word 进程,这将使用安装默认值运行 Word,但这仍然意味着在实例启动时创建设置。 And, depending on what the code does, there may be other limitations/problems involved working under Safe Mode.而且,根据代码的作用,在安全模式下工作可能存在其他限制/问题。

Theoretically , another approach would be to save the settings Registry key(s) - as I recall there are multiple keys where settings are stored, replace them with keys having the required settings, start the "interop" instance, then reverse the process when the "interop" ends.理论上,另一种方法是保存设置注册表项 - 我记得有多个键存储设置,用具有所需设置的键替换它们,启动“互操作”实例,然后在“互操作”结束。 This is in essence essentially what the first approach does and would probably run into issues in an end-user environment without admin privileges, so I only mention it for the sake of completeness.这本质上是第一种方法所做的,并且可能会在没有管理员权限的最终用户环境中遇到问题,所以我只是为了完整起见才提到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM