Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Microsoft Interop Word Automation的DCOM配置设置_C#_.net_Office Interop_Com Interop_Dcom - Fatal编程技术网

C# Microsoft Interop Word Automation的DCOM配置设置

C# Microsoft Interop Word Automation的DCOM配置设置,c#,.net,office-interop,com-interop,dcom,C#,.net,Office Interop,Com Interop,Dcom,我正在使用Microsoft Office Interop Word使用C#生成文档。为使文档生成工作正常,应在Dcom配置设置下为“Microsoft Office Word 97-2003文档”设置一个条目,如下所示: 首次安装Microsoft Office时,常规选项卡下的本地路径具有正确的路径。如果我随后将计算机加入域,然后使用域用户重新启动系统,本地路径将变为空白,并且应用程序不会生成文档并给出错误信息 即使我先将计算机加入域,然后使用域用户登录,然后安装Microsoft Off

我正在使用Microsoft Office Interop Word使用C#生成文档。为使文档生成工作正常,应在
Dcom配置设置下为
“Microsoft Office Word 97-2003文档”
设置一个条目,如下所示:

首次安装Microsoft Office时,
常规选项卡下的
本地路径
具有正确的路径。如果我随后将计算机加入域,然后使用域用户重新启动系统,
本地路径
将变为空白,并且应用程序不会生成文档并给出错误信息

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

是什么导致
Local Path
的值变为空

这一切都是在虚拟机上进行的,自动化这个词在域帐户上工作,正如我在加入域的物理机上看到的那样

UPDATE: What my application is doing:
我的应用程序中有4-5个组件

第一个是VSTO Word加载项,它与Microsoft Word集成,我们在其中创建新文档,其中包含一些也保存在数据库中的表达式。表达式上还有一些条件,它们也可以嵌套。表达式包含保存在数据库中的XSD文件中的架构元素。创建此类文档后,其WordML将保存在数据库中。这一切都是在VSTO AddIn中完成的

第二个是Web服务,它从另一个组件接收输入xml,该组件向上面的XSD确认模式元素已从XSD嵌入到通过VSTO addIn创建的文档中的表达式中。此web服务检查验证和其他几个任务。然后,它从数据库中获取相应word文档的WordML,并将其传递给word Interop,后者使用其API递归地遍历它,以使用输入xml中的实际值替换模式元素。然后将WordML作为word文档保存到文件中

这还会在保存文档之前将模板附加到文档。它使用Word Interop的另存为功能将文件另存为PDF

更新: 我再次浏览了我的完整应用程序,并了解到我们正在通过解析Office Open XML来完成所有工作(例如,为word文档提供输入),但我们使用word Automation所做的唯一工作如下:

  • 使用Word Interop将生成的WordML保存为Word格式文件之一
  • 将生成的WordML导出到PDF文件
  • 将多个WordML合并到单个word文档文件中
  • 获取它的XML
  • 所有这四个代码如下所示,仅显示代码的相关部分:

    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);
    
    要合并多个文件,请执行以下操作:

    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;
    }
    
    Microsoft.Office.Interop.Word.Document doc=null;
    Microsoft.Office.Interop.Word.Section=null;
    对象sectionBreakNextPage=(对象)WdBreakType.wdSectionBreakNextPage;
    可见=false;
    doc=this.WordApplication.Documents.Add(ref-parammassing,ref-parammassing,ref-parammassing,ref-parammassing,ref-parammassing);
    如果(doc!=null)
    {
    doc.Activate();
    int fileCount=sourceFiles.Length;
    字符串文件名=String.Empty;
    对于(int fileIndex=0;fileIndex
    现在,我收到以下错误:

    消息筛选器指示应用程序正忙。(来自HRESULT的异常:0x8001010A(RPC_E_SERVERCALL_RETRYLATER))


    这一切都可以不用自动化这个词来完成吗?

    我认为您应该阅读并尝试另一种解决问题的方法,而不是试图修复和处理该错误:

    (…)Microsoft目前不建议也不支持从任何无人参与、非交互式客户端应用程序或组件(包括ASP、DCOM和NT服务)自动化Microsoft Office应用程序,因为Office在此环境中运行时可能会表现出不稳定的行为和/或死锁(…)

    其中一些
    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(); 
      } 
    }