用C#实现word文档合并

来源:互联网 发布:sql批量删除存储过程 编辑:程序博客网 时间:2024/04/28 05:41

现在要实现这个功能,先拷贝一段代码过来,

再试验能不能用。

public   static   void   MergeDocoument(   )  
  {  
   
   
  strTemplateName   =   HttpContext.Current.Server.MapPath("../VAULTS/"+nTemplateID.ToString()+"/"+strTemplateName+".doc"   );  
   
  object   falseValue   =   false;  
  object   missing   =   System.Reflection.Missing.Value;  
  object   TemplateFileName   =   strTemplateName;  
  Word.Application   wordApp   =   new     Word.ApplicationClass();  
   
  Word.Document   wordDoc   =   wordApp.Documents.Add(ref   missing,   ref   missing,ref   missing,   ref   missing);  
  wordDoc.Activate();  
   
  string   strFileName   =   string.Empty;  
   
   
  wordApp.Selection.InsertFile(   strFileName,ref   missing,ref   falseValue,ref   falseValue,ref   falseValue);  
   
  wordDoc.SaveAs(ref   TemplateFileName,ref   missing,   ref   missing,ref   missing,   ref   missing,ref   missing,   ref   missing,ref   missing,   ref   missing,ref   missing,   ref   missing,ref   missing,   ref   missing,ref   missing,   ref   missing,ref   missing);  
  wordDoc.Close(ref   missing,   ref   missing,   ref   missing);    
  wordApp.Quit(ref   missing,   ref   missing,   ref   missing);    
   
  if   (   wordDoc   !=   null   )  
  {  
  System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc);  
  wordDoc   =   null;  
  }  
  if   (   wordApp   !=   null   )  
  {  
  System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);  
  wordApp   =   null;  
  }  
  GC.Collect();  
  }   
 不是我写的哎,是我马上要用,先试验能不能用。再把问题贴出来

原创粉丝点击