微软互操作的Word自动化DCOM配置设置 [英] DCOM Config settings for Microsoft Interop Word Automation

查看:1596
本文介绍了微软互操作的Word自动化DCOM配置设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Microsoft Office互操作字来生成使用C#文件。为了使文档生成工作,应为Microsoft Office Word中97 - 2003文档中的条目 DCOM配置设置下,如下所示:

本地路径常规选项卡有一个正确的路径是先安装了Microsoft Office时。如果我再将计算机加入到域,然后重新启动系统,域用户,在​​本地路径变成空白,应用程序不会生成的文件,并给出错误

即使我将计算机加入域,然后再登录使用域用户,然后安装Microsoft Office时,本地路径显示正确,然后再重新启动后,再次变为空白。同时,在同一时间,如果我登录的本地用户路径仍然存在。

是什么原因造成本地路径的值变为空白?

这所有的设置是在虚拟机上的字自动化工程,因为我已经看到它工作在物理机上加入域的域帐户。

 更新:什么我的应用程序是这样做的:
 

有4-5个组成部分在我的应用程序。

首先是一个VSTO词外接程序,它集成了Microsoft Word中,我们创建包含某些EX pressions,它们也保存在数据库中的新文档。还有在实施例pressions条件和它们也可以嵌套。防爆pressions包含从保存在数据库XSD文件模式元素。一旦该类型的文件被创建,其WordML中被保存在数据库中。这一切都在VSTO外接程序完成的。

二是接收来自证实上述XSD从该架构元素嵌入到前pressions通过VSTO加载项创建的文档中的另一个组件的输入XML的Web服务。此Web服务检查验证和其他几个任务。然后它获取相应字文档的WordML中从数据库中,并将其传递到Word互其中使用它的API,遍历它递归取代其从输入的xml实际值的模式元素。这则WordML中保存到一个文件作为word文档。

这也节省了之前附加一个模板文件。它使用Word互操作的另存为功能也将文件保存为PDF格式。

  

更新:   我已经通过我的完整的应用程序又走了,才知道,我们正在做的所有的东西通过解析的Office Open XML(例如,用于喂养输入到Word文档),但我们使用Word自动化正在做的唯一的事情是以下几点:

  1. 在使用Word互操作将生成的WordML保存为Word格式文件之一。
  2. 导出生成的WordML PDF文件。
  3. 在合并几个WordMLs成一个单一的Word文档文件。
  4. 获取XML吧。

这四种codeS如下与code只有相关部分:

  Microsoft.Office.Interop.Word.Document wordDocument = NULL;
反对TEMPLATENAME =templateFile.dotm;
wordDocument = this.WordApplication.Documents.Add(REF失踪,失踪参考,参考失踪,失踪参考);
wordDocument.Range(参考丢失,裁判丢失)。文=;
wordDocument.set_AttachedTemplate(REF TEMPLATENAME);

wordDocument = this.WordApplication.Documents.Open(
                   裁判objSourceFilePath,裁判oFalse,裁判oTrue,
                   裁判oMissing,裁判oMissing,裁判oMissing,
                   裁判oMissing,裁判oMissing,裁判oMissing,
                   裁判oMissing,裁判oMissing,裁判oMissing,
                   裁判oMissing,裁判oMissing,裁判oMissing,
                   裁判oMissing);
wordDocument.ExportAsFixedFormat(
        strTargetPath,
        targetFormat,
        paramOpenAfterExport,
        paramExportOptimizeFor,
        paramExportRange,
        paramStartPage,
        paramEndPage,
        paramExportItem,
        paramIncludeDocProps,
        paramKeepIRM,
        paramCreateBookmarks,
        paramDocStructureTags,
        paramBitmapMissingFonts,
        paramUseISO19005_1,
        裁判oMissing);

反对SaveToFormat = SaveToFormat = Microsoft.Office.Interop.Word.WdSaveFor​​mat.wdFormatDocument97;
wordDocument.SaveAs(REF objTargetFilePath,裁判SaveToFormat,裁判oMissing,裁判oMissing,裁判oMissing,裁判oMissing,裁判oMissing,裁判oMissing,裁判oMissing,裁判oMissing,裁判oMissing,裁判oMissing,裁判oMissing,裁判oMissing,裁判oMissing,裁判oMissing);
 

有关合并几个文件:

  Microsoft.Office.Interop.Word.Document DOC = NULL;
Microsoft.Office.Interop.Word.Section部分= NULL;
对象sectionBreakNextPage =(对象)WdBreakType.wdSectionBreakNextPage;

WordApp.Visible = FALSE;
DOC = this.WordApplication.Documents.Add(REF paramMissing,裁判paramMissing,裁判paramMissing,裁判paramMissing);

如果(文件!= NULL)
{
    doc.Activate();
    INT fileCount = sourceFiles.Length;
    字符串文件名=的String.Empty;

    对于(INT fileIndex = 0; fileIndex< fileCount; fileIndex ++)
    {
        文件名=的源文件[fileIndex]
        如果(System.IO.File.Exists(文件名))
        {
            部分= doc.Sections.Last;
            //脱钩当前部分的标题和放大器;页脚从previous节的头和放大器;页脚
            section.Headers [WdHeaderFooterIndex.wdHeaderFooterFirstPage] .LinkTo previous = FALSE;
            section.Footers [WdHeaderFooterIndex.wdHeaderFooterFirstPage] .LinkTo previous = FALSE;
            section.Headers [WdHeaderFooterIndex.wdHeaderFooterPrimary] .LinkTo previous = FALSE;
            section.Footers [WdHeaderFooterIndex.wdHeaderFooterPrimary] .LinkTo previous = FALSE;
            section.Headers [WdHeaderFooterIndex.wdHeaderFooterEvenPages] .LinkTo previous = FALSE;
            section.Footers [WdHeaderFooterIndex.wdHeaderFooterEvenPages] .LinkTo previous = FALSE;

            section.Range.InsertFile(文件名,参考paramMissing,裁判paramMissing,裁判paramMissing,裁判paramMissing);
            //如果是最后一次迭代,do'nt插入休息
            如果(fileIndex< fileCount  -  1)
            {
                对象具有rangeStart =(对象)(section.Range.End  -  1);
                doc.Range(REF具有rangeStart,裁判paramMissing).InsertBreak(REF sectionBreakNextPage);
            }
        }
    }
    doc.SaveAs(REF的TargetFile,裁判wordFormat,裁判paramMissing,
        裁判paramMissing,裁判paramMissing,裁判paramMissing,
        裁判paramMissing,裁判paramMissing,裁判paramMissing,
        裁判paramMissing,裁判paramMissing,裁判paramMissing,
        裁判paramMissing,裁判paramMissing,裁判paramMissing,
        裁判paramMissing);
    返回true;
}
 

现在,我收到以下错误:

消息过滤器显示应用程序正忙。 (从HRESULT异常:0x8001010A(RPC_E_SERVERCALL_RETRYLATER))

可这一切都在不使用Word自动化做?

解决方案

而不是试图解决和处理的错误,我想你应该读的这个,然后尝试另一种方法,您的问题:

(...)微软目前并不提倡,不支持,Microsoft Office应用程序的自动化,从任何无人参与的非交互式客户端应用程序或组件(包括ASP,DCOM和NT服务),因为办公室可以表现出不稳定的行为和/或在此环境中运行时死锁。 (...)

有些建议在KB的替代方案是:

(...) Microsoft强烈推荐了一些替代品,不需要办公室要安装服务器端的,而且可以比自动化更高效地执行最常见的任务,更迅速。在您的项目包括办公室作为服务器端组件,可以考虑的选择。

大多数服务器端自动化任务包括创建或编辑文档。 Office 2007的支持,让开发人员创建,编辑,阅读,并在服务器端转换文件内容的新的Open XML文件格式。这些文件格式使用System.IO.Package.IO命名空间在Microsoft .NET 3.x的框架,而无需使用Office客户端应用程序本身来编辑Office文件。这是从服务处理更改Office文件的建议和支持的方法。 (...)

(...) Microsoft提供的SDK从.NET 3.x的框架操作的Open XML文件格式。有关SDK和有关如何使用SDK来创建或编辑Open XML文件,请访问下面的Microsoft Developer Network的详细信息(MSDN)的网站:

请注意,即使你得到你的问题不动,你的解决方案将难以稳定......在本质上的东西,它似乎是发生的是,你搞砸你的注册表,似乎您的Word重新安装未修复您的注册表,这是有问题的。

在此基础上,我建议你阅读上面的文档,并试图把一个更稳定的解决方案,使用上面的替代品,如Microsoft Office应用程序的自动化,从任何无人参与的非交互式客户端应用程序或组件,这是你的情况下,可以表现出不稳定的行为。

更新1

您有一个Hello World示例这里 。 创建与Open XML文档可以那么容易,因为这样做的:

 公共无效的HelloWorld(可采用DocName字符串)
{
  //创建一个字处理文档。
  使用(Wordpro​​cessingDocument包= Wordpro​​cessingDocument.Create(可采用DocName,Wordpro​​cessingDocumentType.Document))
  {
    //添加一个新的主文档的一部分。
    package.AddMainDocumentPart();

    //创建文档的DOM。
    package.MainDocumentPart.Document =
      新的文件(
        新的机构(
          新的第(
            新的运行(
              新文本(的Hello World!)))));

    //将更改保存到主文档的一部分。
    package.MainDocumentPart.Document.Save();
  }
}
 

注意

我可以在这里花了几个小时,试图解决您的注册表,但你可以看到的在我的博客这篇文章,这些问题是巨大的头痛,你的情况,即使你找到一个方法来解决它,它不会是一个维护或任一可伸缩解决方案,我当然认为。

更新2

<据时,这些配置诸如本地路径从注册表中提取,并且不修改:

(...)常规选项卡提供有关应用程序的一般信息。此选项卡显示应用程序名称,类型(本地服务器或远程服务器)和位置(本地路径或远程计算机)。这些设置是不可修改通过DCOM配置界面。

常规标签检索所有从下面的注册表项的子项的信息: HKEY_CLASSES_ROOT \ CLSID {... CLSID ...} 其中{... CLSID ...}是唯一的CLSID为当前正在查看的对象服务器。 (...)

所以!运行>注册表编辑器>转到HKEY_CLASSES_ROOT \ CLSID,然后去编辑菜单,单击查找,过滤用钥匙,把你的applicationID那里。你应该找到这样的看法。

现在找到适合您的DCOM注册表项后,展开它,你应该看到一个LocalServer32,属性(默认)握着你的本地路径值,尝试改变它相同的路径在新的Oracle虚拟框。

如果这个工程,测试,如果重新启动,并与您登录,如果它确实域用户帐户,后值保持巨大的,如果不是,运行一个批处理运行一个.reg文件来执行此修改,在每次登录。

警告:然而,这是不好的东西,我强烈,强烈建议你去了其他方式,这是不是这样做的方式。

更新3

关于MS-WORD自动化错误:消息过滤器显示应用程序正忙,你要这个问题<一个很好的答复href="http://social.msdn.microsoft.com/Forums/vstudio/en-US/70ef972b-51b6-4ece-a4af-d6b4e111eea5/msword-automation-error-the-message-filter-indicated-that-the-application-is-busy?forum=vsto"相对=nofollow>此处我要举了一下上面的联系,进一步了解为什么会发生错误:

(...)这个问题是在Word对象时,调用到不支持多线程的事实。由于它们是通过COM暴​​露任意客户端,可能性是存在的多个线程可能会尝试在对象中同时执行code。为prevent这种情况的发生,将排队起来,并只允许一次一个调用执行所有来电序列。这是通过包装了每个呼叫的详细信息,并发布消息到Word完成。当Word程序,消息,电话会在Word自带的主线程中执行。这种方法的问题在于,如果Word忙着做别的事情,当来电时,主叫方将不得不等待。 (...)

关于合并,这工具声称能够合并OpenXML文档中,我从来没有使用过,但我会试试看(如果我是你)。

(...) PowerTools的开放XML包含源$ C ​​$ c和指导完成使用Open XML SDK各种常见任务,如: - DOCX高保真转换为HTML / CSS使用HtmlConverter.cs; - 使用DocumentBuilder.cs合并和拆分DOCX文档; - 使用presentationBuilder.cs合并和拆分PPTX presentations; - 接受跟踪修订使用RevisionAccepter.cs DOCX文档; - 搜索和替换文本的DOCX文档使用TextReplacer.cs (...)

最后生成的PDF文件,从您的Word文档,可以使用此工具这里

因此​​,大家可以看到,一旦多了,你可以继续处理的Word自动化(暗面),也可以加入轻的边的部队。)

I am using Microsoft Office Interop Word to generate documents using C#. In order for the document generation to work, there should be an entry for the "Microsoft Office Word 97 - 2003 Document" under the Dcom Config Settings as shown below:

The Local Path under the General Tab has a correct path when Microsoft Office is first installed. If I then join the computer to a Domain, and then restart the system with a Domain user, the Local Path becomes blank and the application doesn't generate the documents and gives error.

Even if I join the computer to Domain first and then login with Domain user and then install the Microsoft Office, the Local Path appears correct first and then after a restart, it becomes blank again. While, at the same time, if I login with the Local User, the Path is still there.

What is causing the value of Local Path to go blank?

This all setup is on virtual machines and the word automation works on a domain account as I have seen it working on a physical machine joined to domain.

UPDATE: What my application is doing:

There are 4-5 components in my application.

The first is a VSTO Word AddIn, which integrates with Microsoft Word, where we create new documents that contain some Expressions that are also saved in the database. There are also conditions on the Expressions and they can be nested also. Expressions contain schema elements from XSD files which are saved in database. Once this type of document is created, its WordML is saved in the database. This all is done in VSTO AddIn.

The second is a Web Service which receives an input xml from another component that confirms to the XSD above from which the schema elements were embedded into the expressions in the document created through VSTO addIn. This web service checks for the validations and several other tasks. It then gets the WordML of the corresponding word document from the database and passes it to the Word Interop which using its APIs, iterates through it recursively to replace the schema elements with their actual values from the input xml. This then saves the WordML to a file as word document.

This also attaches a template to the document before saving it. It uses the SaveAs functionality of Word Interop to also save the file as PDF.

UPDATE: I have again gone through my complete application and came to know that we are doing all things by parsing the Office Open XML (e.g. for feeding the input to the word document), but the only things that we are doing using Word Automation are following:

  1. Using Word Interop to save the generated WordML as one of the Word Format Files.
  2. Exporting the generated WordML to the PDF file.
  3. Merging several WordMLs into a single word document file.
  4. Fetching the XML for it.

All these four codes are shown below with only relevant parts of code:

Microsoft.Office.Interop.Word.Document wordDocument = null;
object templateName = "templateFile.dotm";
wordDocument = this.WordApplication.Documents.Add(ref missing, ref missing, ref missing, ref missing);
wordDocument.Range(ref missing, ref missing).Text = "";
wordDocument.set_AttachedTemplate(ref templateName);

wordDocument = this.WordApplication.Documents.Open(
                   ref objSourceFilePath, ref oFalse, ref oTrue,
                   ref oMissing, ref oMissing, ref oMissing,
                   ref oMissing, ref oMissing, ref oMissing,
                   ref oMissing, ref oMissing, ref oMissing,
                   ref oMissing, ref oMissing, ref oMissing,
                   ref oMissing);
wordDocument.ExportAsFixedFormat(
        strTargetPath,
        targetFormat,
        paramOpenAfterExport,
        paramExportOptimizeFor,
        paramExportRange,
        paramStartPage,
        paramEndPage,
        paramExportItem,
        paramIncludeDocProps,
        paramKeepIRM,
        paramCreateBookmarks,
        paramDocStructureTags,
        paramBitmapMissingFonts,
        paramUseISO19005_1,
        ref oMissing);

object SaveToFormat = SaveToFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument97;
wordDocument.SaveAs(ref objTargetFilePath, ref SaveToFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

For Merging several files:

Microsoft.Office.Interop.Word.Document doc = null;
Microsoft.Office.Interop.Word.Section section = null;
object sectionBreakNextPage = (object)WdBreakType.wdSectionBreakNextPage;

WordApp.Visible = false;
doc = this.WordApplication.Documents.Add(ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing);

if (doc != null)
{
    doc.Activate();
    int fileCount = sourceFiles.Length;
    String fileName = string.Empty;

    for (int fileIndex = 0; fileIndex < fileCount; fileIndex++)
    {
        fileName = sourceFiles[fileIndex];
        if (System.IO.File.Exists(fileName))
        {
            section = doc.Sections.Last;
            //delink the current section's header & footer from previous section's header & footer
            section.Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].LinkToPrevious = false;
            section.Footers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].LinkToPrevious = false;
            section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].LinkToPrevious = false;
            section.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].LinkToPrevious = false;
            section.Headers[WdHeaderFooterIndex.wdHeaderFooterEvenPages].LinkToPrevious = false;
            section.Footers[WdHeaderFooterIndex.wdHeaderFooterEvenPages].LinkToPrevious = false;

            section.Range.InsertFile(fileName, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing);
            //if it is last iteration, do'nt insert break
            if (fileIndex < fileCount - 1)
            {
                object rangeStart = (object)(section.Range.End - 1);
                doc.Range(ref rangeStart, ref paramMissing).InsertBreak(ref sectionBreakNextPage);
            }
        }
    }
    doc.SaveAs(ref targetFile, ref wordFormat, ref paramMissing,
        ref paramMissing, ref paramMissing, ref paramMissing,
        ref paramMissing, ref paramMissing, ref paramMissing,
        ref paramMissing, ref paramMissing, ref paramMissing,
        ref paramMissing, ref paramMissing, ref paramMissing,
        ref paramMissing);
    return true;
}

Right now, I am receiving the following error:

The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))

Can this all be done without using the Word Automation?

解决方案

Instead of trying to fix and deal with that error, I think you should read this and then try another approach to your problem:

(...) Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when run in this environment. (...)

Some of the alternatives recommended in that KB are:

(...) Microsoft strongly recommends a number of alternatives that do not require Office to be installed server-side, and that can perform most common tasks more efficiently and more quickly than Automation. Before you involve Office as a server-side component in your project, consider alternatives.

Most server-side Automation tasks involve document creation or editing. Office 2007 supports new Open XML file formats that let developers create, edit, read, and transform file content on the server side. These file formats use the System.IO.Package.IO namespace in the Microsoft .NET 3.x Framework to edit Office files without using the Office client applications themselves. This is the recommended and supported method for handling changes to Office files from a service. (...)

And

(...) Microsoft provides an SDK for manipulating Open XML file formats from the .NET 3.x Framework. For more information about the SDK and about how to use the SDK to create or edit Open XML files, visit the following Microsoft Developer Network (MSDN) Web sites:

Note, that even if you get your problem fixed, your solution will hardly be stable... In essence what, it seems to be happening is that you messed your registry and it seems that your Word reinstallation is not fixing your registry, and that is problematic.

Based on this, I recommend you to read the above documentation and to try put together a more stable solution using the above alternatives, as Automation of Microsoft Office applications from any unattended, non-interactive client application or component, which is your case, may exhibit unstable behaviors.

UPDATE 1

You have an Hello World example here. Creating a document with Open XML can be as easy as doing this:

public void HelloWorld(string docName) 
{
  // Create a Wordprocessing document. 
  using (WordprocessingDocument package = WordprocessingDocument.Create(docName, WordprocessingDocumentType.Document)) 
  {
    // Add a new main document part. 
    package.AddMainDocumentPart(); 

    // Create the Document DOM. 
    package.MainDocumentPart.Document = 
      new Document( 
        new Body( 
          new Paragraph( 
            new Run( 
              new Text("Hello World!"))))); 

    // Save changes to the main document part. 
    package.MainDocumentPart.Document.Save(); 
  } 
}

Note

I could spent here hours, trying to solve your registry, but as you can see in this article in my blog, those problem are huge headaches, and in your case, even if you find a way to solve it, it will not be a maintainable or either scalable solution, in my opinion of course.

UPDATE 2

According to this, those configurations such as local path are extracted from the registry and are not modifiable:

(...) The General tab provides general information about the application. This tab displays the Application name, type (local server or remote server), and location (local path or remote computer). These settings are not modifiable through the DCOM Config interface.

The General Tab retrieves all of its information from subkeys of the following registry key: HKEY_CLASSES_ROOT\CLSID{...CLSID...} where {...CLSID...} is the unique CLSID for the Object Server currently being viewed. (...)

So! Run > regedit > Go to HKEY_CLASSES_ROOT\CLSID, then go to Edit menu and click Find, filter by key and put your ApplicationID there. You should find it this way.

Now after finding the registry entry for your DCOM, expand it, you should see a LocalServer32, the property (Default) holds your Local Path value, try change it the same path as in your new Oracle Virtual Box.

If this works, test if the value hold after restarting and logging in with you Domain User account if it does, great, if not, run a batch to run a .reg file to perform this modification, on every login.

Warning: Nevertheless, this is bad stuff, I strongly, strongly encourage you to go the other way around, this is not the way to do it.

UPDATE 3

Regarding the "MS-WORD AUTOMATION ERROR : "The message filter indicated that the application is busy", you have a very good reply to that problem here. I'll cite a bit of the above link, for further understanding of why that error happens:

(...) That issue is the fact that the Word objects you are calling into do not support multiple threading. Since they are exposed to arbitrary clients via COM, the possibility exists that multiple threads could attempt to simultaneously execute code within the object. To prevent this from happening, will serialize all incoming calls by queuing them up and only allowing one call at a time to execute. This is done by packaging up the details of each call and posting a message to Word. When Word processes, the message, the call will execute on Word's own main thread. The problem with this approach is that if Word is busy doing something else when the call comes in, the caller will have to wait. (...)

About the merging, this tool claims to be capable of merging OpenXML documents, I never used it, but I would give it a try (if I were you).

(...) PowerTools for Open XML contains source code and guidance for accomplishing various common tasks using the Open XML SDK, such as: - High-fidelity conversion of DOCX to HTML/CSS using HtmlConverter.cs; - Merging and splitting DOCX documents using DocumentBuilder.cs; - Merging and splitting PPTX presentations using PresentationBuilder.cs; - Accepting tracked revisions in DOCX documents using RevisionAccepter.cs; - Searching and replacing text in DOCX documents using TextReplacer.cs (...)

Finally to generate PDFs, from your word documents, you can use this tool here.

So as you can see, once more, you can keep dealing with Word Automation (Dark Side), or you can join the Light Side of the Force :).

这篇关于微软互操作的Word自动化DCOM配置设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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