C# 在word文档中复制表格并粘帖到下一页中
C# 在word文档中复制表格并粘帖到下一页中
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word._Application oWord;
Microsoft.Office.Interop.Word._Document oDoc;
oWord = new Microsoft.Office.Interop.Word.Application();
//显示word文档
oWord.Visible = true;
//取得word文件模板
object fileName = System.Windows.Forms.Application.StartupPath + "\word.doc";
//根据模板生成一个新文档,相当于另存为
oDoc = oWord.Documents.Add(ref fileName, ref oMissing,
ref oMissing, ref oMissing);
//复制第一个表格
oDoc.Tables[1].Select();
oWord.Selection.Copy();
//在这里操作表格中的文本
oDoc.Tables[1].Cell(1, 1).Range.Text = "这是第一个表格";
//下一页
object mymissing = System.Reflection.Missing.Value;
object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
oWord.Selection.EndKey(ref myunit, ref mymissing);
object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
oWord.Selection.InsertBreak(ref pBreak);
//粘贴第一个表格
oWord.Selection.Paste();
oDoc.Tables[2].Cell(1, 1).Range.Text = "这是第二个表格";
bool saveChange = false;
//C#操作Word表格操作
object missing = System.Reflection.Missing.Value;
object template = (object)templateFilePath;
object filename = (object)saveFilePath;
object isVisible = missing;
object readOnly = missing;
object breakType = Word.WdBreakType.wdSectionBreakNextPage;
object isSaveChange = (object)saveChange;
Word.Document doc = null;
//定义一个Word.Application 对象
Word.Application WordApp = new Word.ApplicationClass();
//C#操作Word表格操作之打开文档
doc = WordApp.Documents.Open(ref template,
ref missing,ref readOnly,ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing,ref missing,
ref missing, ref isVisible, ref missing,
ref missing, ref missing, ref missing);
//C#操作Word表格操作之设置页眉文本
WordApp.ActiveWindow.ActivePane.View.SeekView =
Word.WdSeekView.wdSeekCurrentPageHeader;
WordApp.Selection.WholeStory();
WordApp.Selection.TypeText( this.m_titleText );
WordApp.ActiveWindow.ActivePane.View.SeekView =
Word.WdSeekView.wdSeekMainDocument;
//页面设置,设置页面为纵向布局,设置纸张类型为A4纸
doc.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape;
doc.PageSetup.PageWidth = WordApp.CentimetersToPoints(29.7F);
doc.PageSetup.PageHeight = WordApp.CentimetersToPoints(21F);
//C#操作Word表格操作之创建表格及设置表格和单元格属性
object autoFitBehavior = Word.WdAutoFitBehavior.wdAutoFitWindow;
doc.Content.Tables.Add(
WordApp.Selection.Range, totalCount + 1,
totalField - keyCount_1, ref missing,
ref autoFitBehavior);
//C#操作Word表格操作之合并单元隔
doc.Content.Tables[1].Cell(i+1,j).Select();
object moveUnit = Word.WdUnits.wdLine;
object moveCount = 1;
object moveExtend = Word.WdMovementType.wdExtend;
WordApp.Selection.MoveUp(ref moveUnit,
ref moveCount, ref moveExtend);
WordApp.Selection.Cells.Merge();
WordApp.Selection.Cells.VerticalAlignment =
Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
doc.Content.Tables[1].Cell(i+1,1).Range.Text = “单元格内容填充”
//添加表格行
doc.Content.Tables[0].Rows.Add(ref beforeRow);
//C#操作Word表格操作之添加表格列
doc.Content.Tables[0].Columns.Add(ref beforeColumn);
//文本居中
WordApp.Selection.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter;
WordApp.Selection.Cells.VerticalAlignment =
Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
//C#操作Word表格操作之选中单元格文字垂直居中
oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);
Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add(ref beforeRow);
Word.Cell cell = newTable.Cell(1, 1);
cell.Merge(newTable.Cell(1, 2));
C# 在word文档中复制表格并粘帖到下一页中的更多相关文章
- java 在MySQL中存储文件,读取文件(包括图片,word文档,excel表格,ppt,zip文件等)
转自:https://blog.csdn.net/u014475796/article/details/49893261 在设计到数据库的开发中,难免要将图片或文档文件(如word)插入到数据库中的情 ...
- 怎样把Word文档导入Excel表格
Word是现在办公中的基础文件格式了,很多的内容我们都通过Word来进行编辑,那么当我们需要将Word文档里的信息导入到Excel里面的时候,我们应该怎样做呢?下面我们就一起来看一下吧. 操作步骤: ...
- Struts2利用iText导出word文档(包含表格)以提供下载
J2EE ExcelStrutsXML 在公司实习期间,带我的老师让我实现一功能——在显示课表的页面上上点击“导出文件“时能以word文档形式下载课表.将课表导出到excel里的功能他们已经实现了, ...
- JAVAWEB导出word文档,遍历表格数据,导出图片
这是写的另一个导出word方法:https://www.cnblogs.com/pxblog/p/12790904.html 本次使用的是easypoi框架 官方教程:https://opensour ...
- word文档去掉复制过来的背景颜色
选择清除格式
- 2018-10-04 [日常]用Python读取word文档中的表格并比较
最近想对某些word文档(docx)的表格内容作比较, 于是找了一下相关工具. 参考Automate the Boring Stuff with Python中的word部分, 试用了python-d ...
- 2.QT中操作word文档
Qt/Windows桌面版提供了ActiveQt框架,用以为Qt和ActiveX提供完美结合.ActiveQt由两个模块组成: A QAxContainer模块允许我们使用COM对象并且可以 ...
- C# Word文档中插入、提取图片,文字替换图片
Download Files:ImageOperationsInWord.zip 简介 在这篇文章中我们可以学到在C#程序中使用一个Word文档对图像的各种操作.图像会比阅读文字更有吸引力,而且图像是 ...
- java 处理word文档 (含图片,表格内容)
因为本人长期从事Oa相关项目的开发,所以处理word文档,Pdf,Excel等是在所难免的. 1.需求 处理Excel 能够用jxl 或者poi 2需求 用户在系统上填 ...
随机推荐
- ssh框架的小实例(用户登录)
刚学SSH框架写一个小实例,以便以后查看: 本案例简单的实现一个用户登录: 数据库方面就不写了,自己领悟吧!哈哈(根据user.hbm.xml文件就知道了) 我们一般可以创建下面几个包,什么意思呢,自 ...
- linux upstart启动配置
程序名.conf放在/etcc/init/目录下# 注释 description "your-server" author "xxx" start on run ...
- mysql中datetime和timestamp的区别
原文地址:http://database.51cto.com/art/200905/124240.htm 相同 显示 TIMESTAMP列的显示格式与DATETIME列相同.换句话说,显示宽度固定在1 ...
- 移动HTML 5前端性能优化指南(转载)
前端工程师的菜!最近移动Html 5越来越火,想有一个体验流畅的Html 5 应用,这篇优化指南就别放过咯.腾讯的同学将关键的注意点与优化方法都总结出来,全文高能干货,非常值得深度学习 >> ...
- dict字典学习笔记
dict的创建: #第一行初始化指定一个dict d = {'1':'刘刚','2':李萌,'3':89} #key在前,value在后.key ...
- My网页
开始更新|Version:2.46|更新内容:/=====================================//1.新增秒低价次数//2.优化捉鬼停留过久的问题//3.优化其他任务上的效 ...
- 《JavaScript高级程序设计》读书笔记 ---单体内置对象
Global对象Global(全局)对象可以说是ECMAScript 中最特别的一个对象了,因为不管你从什么角度上看,这个对象都是不存在的.ECMAScript 中的Global 对象在某种意义上是作 ...
- Linux系统编程初探系列之一:文件编程
系统函数 int creat(const char* filename,mode_t mode) filename:需要创建的文件名(包含路径,缺省为当前路径) mode:创建模式 常见的创建模式有: ...
- Linux系统安装rar压缩软件
将 hebaodans.com 目录打包为 hebaodans.rar # rar a hebaodans.rar ./hebaodans.com/ 解压 hebaodans.rar 到当前目录 # ...
- Paint Pearls
Paint Pearls 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5009 dp+双向链表优化 看到题目,很自然地可以定义状态:dp[i]表示涂好 ...