我在網上找了些資料
public void Merge(string strOrgDoc, string[] arrCopies, string strOutDoc)
    {
      ApplicationClass objApp = null;      //boxing of default values for COM interop purposes
      object objMissing = Missing.Value;
      object objFalse = false;
      object objTarget = WdMergeTarget.wdMergeTargetSelected;
      object objUseFormatFrom = WdUseFormattingFrom.wdFormattingFromSelected;      try
      {
        objApp = new ApplicationClass();運行在這裏就出錯了,我用的是office 2007,在網上也找了相關資料,設置什麽dcom的Microsoft Office word97-2003中的權限,這裏不管我添加什麽人員,但最後運行是還是出錯.而我在winform中則正常運行,請問是什麽原因,請高手們賜教!!
        object objOrgDoc = strOrgDoc;
        
        Document objDocLast = null;
        Document objDocBeforeLast = null;        objDocLast = objApp.Documents.Open(
          ref objOrgDoc,    //FileName
          ref objMissing,   //ConfirmVersions
          ref objMissing,   //ReadOnly
          ref objMissing,   //AddToRecentFiles
          ref objMissing,   //PasswordDocument
          ref objMissing,   //PasswordTemplate
          ref objMissing,   //Revert
          ref objMissing,   //WritePasswordDocument
          ref objMissing,   //WritePasswordTemplate
          ref objMissing,   //Format
          ref objMissing,   //Enconding
          ref objMissing,   //Visible
          ref objMissing,   //OpenAndRepair
          ref objMissing,   //DocumentDirection
          ref objMissing,   //NoEncodingDialog
          ref objMissing    //XMLTransform
          );        foreach(string strCopy in arrCopies)
        {
          Debug.WriteLine("Merging file " + strCopy);
          objDocLast.Merge(
            strCopy,                //FileName    
            ref objTarget,          //MergeTarget
            ref objMissing,         //DetectFormatChanges
            ref objUseFormatFrom,   //UseFormattingFrom
            ref objMissing          //AddToRecentFiles
            ); 
          objDocBeforeLast = objDocLast;
          objDocLast = objApp.ActiveDocument;
          Debug.WriteLine("The active document is " + objDocLast.Name);          if (objDocBeforeLast != null)
          {
            Debug.WriteLine("Closing " + objDocBeforeLast.Name);
            objDocBeforeLast.Close(
              ref objFalse,     //SaveChanges
              ref objMissing,   //OriginalFormat
              ref objMissing    //RouteDocument
              );
          }
            
          
        }        object objOutDoc = strOutDoc;
              objDocLast.SaveAs(    
          ref objOutDoc,      //FileName
          ref objMissing,     //FileFormat
          ref objMissing,     //LockComments
          ref objMissing,     //PassWord     
          ref objMissing,     //AddToRecentFiles
          ref objMissing,     //WritePassword
          ref objMissing,     //ReadOnlyRecommended
          ref objMissing,     //EmbedTrueTypeFonts
          ref objMissing,     //SaveNativePictureFormat
          ref objMissing,     //SaveFormsData
          ref objMissing,     //SaveAsAOCELetter,
          ref objMissing,     //Encoding
          ref objMissing,     //InsertLineBreaks
          ref objMissing,     //AllowSubstitutions
          ref objMissing,     //LineEnding
          ref objMissing      //AddBiDiMarks
          );        foreach(Document objDocument in objApp.Documents)
        {
          objDocument.Close(
            ref objFalse,     //SaveChanges
            ref objMissing,   //OriginalFormat
            ref objMissing    //RouteDocument
            );
        }
        
      }
      finally
      {
        objApp.Quit(          
          ref objMissing,     //SaveChanges
          ref objMissing,     //OriginalFormat
          ref objMissing      //RoutDocument
          );
        objApp = null;
      }
    }

解决方案 »

  1.   

    都是牛人……问题都TMD的牛……不牛的我只好坐等高人学习……
      

  2.   

    自已頂,在線等,設置了好多,給了個everyone 的權限為完全控制了!!
      

  3.   

    怎麽回事呢??不然誰解決過的,說下.在dcom中的Microsoft word97-2003的clsid並不是
    {000209FF-0000-0000-C000-000000000046};
    但我的程序是提示這個錯誤.我想原因是我的office 是2007的原因吧.所以我也不知道怎麽設置好,跑去注冊表把word.application12的增加權限,但是也不行
    暈死.求救!!
      

  4.   

    不知道呀, 用ILDASM查查看。
      

  5.   

    我解决过此问题,就是DCOM的设置!
    设置完权限重启下!
      

  6.   

    不行啊??難道是我office 2007 或者裝的是xp系統的原因,同事裝的是2003系統和office 2003,他調用excel可以的.設置一樣!