首先将word文档路径保存在List<string>中,新建一个word文档对象并循环List打开对应的word,之后拷贝文档,在新文档中粘贴并且粘贴前先插入换行符。最后保存新文档,并销毁进程。
InBlock.gif protected void Button1_Click( object sender, EventArgs e)    
InBlock.gif
InBlock.gif  {    
InBlock.gif
InBlock.gif   // object worPath = @"C:\";    
InBlock.gif
InBlock.gif   object path = @"C:\Test合并word.doc";    
InBlock.gif
InBlock.gif  List< string> pathList = new List< string>();    
InBlock.gif
InBlock.gif  pathList.Add( @"C:\word1.doc");    
InBlock.gif
InBlock.gif  pathList.Add( @"C:\word2.doc");    
InBlock.gif
InBlock.gif   object objDocType = WdDocumentType.wdTypeDocument;    
InBlock.gif
InBlock.gif   object type = WdBreakType.wdSectionBreakContinuous;    
InBlock.gif
InBlock.gif  Application wordApp; //Word应用程序变量    
InBlock.gif
InBlock.gif  Document newWordDoc; //Word文档变量    
InBlock.gif
InBlock.gif   object readOnly = false;    
InBlock.gif
InBlock.gif   object isVisible = false;    
InBlock.gif
InBlock.gif  wordApp = new ApplicationClass(); //初始化    
InBlock.gif
InBlock.gif   //由于使用的是COM库,因此有许多变量需要用Missing.Value代替    
InBlock.gif
InBlock.gif  Object Nothing = Missing.Value;    
InBlock.gif
InBlock.gif   //wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);    
InBlock.gif
InBlock.gif  newWordDoc = wordApp.Documents.Add( ref Nothing, ref Nothing, ref Nothing, ref Nothing);    
InBlock.gif
InBlock.gif   for ( int i = 0; i < pathList.Count; i++)    
InBlock.gif
InBlock.gif  {    
InBlock.gif
InBlock.gif  Document openWord;    
InBlock.gif
InBlock.gif   object obj = pathList[i];    
InBlock.gif
InBlock.gif  openWord = wordApp.Documents.Open( ref obj, ref Nothing, ref readOnly, ref Nothing,    
InBlock.gif
InBlock.gif   ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,    
InBlock.gif
InBlock.gif   ref Nothing, ref isVisible, ref Nothing, ref Nothing, ref Nothing, ref Nothing);    
InBlock.gif
InBlock.gif  openWord.Select();    
InBlock.gif
InBlock.gif  openWord.Sections[1].Range.Copy();    
InBlock.gif
InBlock.gif   //string str= Clipboard.GetText(TextDataFormat.Text);    
InBlock.gif
InBlock.gif   // str+="\n\n";    
InBlock.gif
InBlock.gif   // Clipboard.SetData(DataFormats.Text, str);    
InBlock.gif
InBlock.gif   object start = 0;    
InBlock.gif
InBlock.gif  Range newRang = newWordDoc.Range( ref start, ref start);    
InBlock.gif
InBlock.gif  newWordDoc.Sections[1].Range.InsertBreak( ref type); //插入换行符    
InBlock.gif
InBlock.gif  newWordDoc.Sections[1].Range.PasteAndFormat(WdReco veryType.wdPasteDefault);    
InBlock.gif
InBlock.gif  openWord.Close( ref Nothing, ref Nothing, ref Nothing);    
InBlock.gif
InBlock.gif  }    
InBlock.gif
InBlock.gif   object format = WdSaveFormat.wdFormatDocument; //.wdFormatDocumentD efault;    
InBlock.gif
InBlock.gif   //将wordDoc文档对象的内容保存为DOCX文档    
InBlock.gif
InBlock.gif  newWordDoc.SaveAs( ref path, ref format, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);    
InBlock.gif
InBlock.gif   //关闭wordDoc文档对象    
InBlock.gif
InBlock.gif  newWordDoc.Close( ref Nothing, ref Nothing, ref Nothing);    
InBlock.gif
InBlock.gif   //关闭wordApp组件对象    
InBlock.gif
InBlock.gif  wordApp.Quit( ref Nothing, ref Nothing, ref Nothing);    
InBlock.gif
InBlock.gif  Console.WriteLine(path + " 创建完毕!");    
InBlock.gif
InBlock.gif  Console.ReadLine();    
InBlock.gif
InBlock.gif  }