c#将一个word中的内容放到另一个word的表格中
2013-06-07 09:59
309 查看
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
相关文章推荐
- C# 复制一个Word文档的部分或全部内容到另一个Word文档
- c# 将word内容放到Excel的一个单元格中
- C#控制台基础 file.readalltext把小容量的txt中的内容放到一个string里
- C#中如何快速地将一个表(datatable)的内容复制给另一个表
- 复制一个Word文档的部分或全部内容到另一个Word文档
- C#控制台基础 file.readalllines一行一行的读取一个txt文本,把txt中的内容放到一个string数组里
- 在C#中向Word 中现有的表格中加行一行,并给每个单元格一个值,要怎么写呀?
- C#打开WORD文档内容并显示(未完善表格图片等排版显示的处理)
- ASP.NET C#如何读取word,写入word,复制内容到另一个word文档,批量修改文件名
- C#打开WORD文档内容并显示(未完善表格图片等排版显示的处理)
- C#在一个form中改变另一个form中控件的内容、C#做登录界面并且密码显示为*
- [转]ASP.NET C#如何读取word,写入word,复制内容到另一个word文档,批量修改文件名
- c#.net 将网页内容转换成word或excel文档
- 【20090313-01】C#读取Word表格中的数据 (转)
- C#采用OpenXml给Word文档添加表格
- C#实现Word中表格信息读取
- delphi 把一个表的内容转到另一个表暂存时出错的解决方法。
- Ajax学习之在一个页面中异步的加载另一个页面内容
- C#中锁定Word内容,样把人家的锁定内容破解了
- C#获取Word文档页数,并跳转到指定的页面获取内容,且插入分页符