• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#中的trycatchfinally发布时间:2022-07-10
下一篇:
C#/VB.NET在Excel单元格中应用多种字体格式发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap