c#将一个word中的内容放到另一个word的表格中

using Word = Microsoft.Office.Interop.Word;
using Excel = Microsoft.Office.Interop.Excel;
///
<summary> /// 将一个word中的内容拷贝到另外一个word中的表格中 /// 前提是目标word中有一个表格 /// </summary> /// <param name="source">源文件</param> /// <param name="target">目标文件</param> /// <param name="row"></param> /// <param name="col"></param> public void WordCopy2WordTable(string source,string target,int row,int col) { object oMissing = System.Reflection.Missing.Value; Word._Application oWord; Word._Document oDoc ,oTarget; oWord = new Word.Application(); oWord.Visible = true; object fileName = source; oDoc = oWord.Documents.Open(ref fileName, 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, ref oMissing); oDoc.ActiveWindow.Selection.WholeStory(); oDoc.ActiveWindow.Selection.Copy(); oDoc.Close(); object targetfile = target; oTarget = oWord.Documents.Open(ref targetfile, 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, ref oMissing); Word.Table table = oTarget.Tables[1]; table.Cell(row, col).Range.Paste(); oTarget.Save(); oTarget.Close(); object savechange = true; oWord.Quit(savechange, oMissing, oMissing); }

适合执行一次,多次的话 需要修改中间开关文档,需要配置com组件,具体配置

http://www.cnblogs.com/mengxingxinqing/archive/2013/06/07/3123344.html

原文地址:https://www.cnblogs.com/mengxingxinqing/p/3123284.html