黄聪:C#操作Word表格的常见操作(转)
几种常见C#操作Word表格操作有哪些呢?让我们来看看具体的实例演示:
- 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表格的常见操作(转)的更多相关文章
- 转发:VB程序操作word表格(文字、图片)
很多人都知道,用vb操作excel的表格非常简单,但是偏偏项目中碰到了VB操作word表格的部分,google.baidu搜爆了,都没有找到我需要的东西.到是搜索到了很多问这个问题的记录.没办法,索性 ...
- Java 操作Word表格——创建嵌套表格、添加/复制表格行或列、设置表格是否禁止跨页断行
本文将对如何在Java程序中操作Word表格作进一步介绍.操作要点包括 如何在Word中创建嵌套表格. 对已有表格添加行或者列 复制已有表格中的指定行或者列 对跨页的表格可设置是否禁止跨页断行 创建表 ...
- Java 操作Word表格
本文将对如何在Java程序中操作Word表格作进一步介绍.操作要点包括 如何在Word中创建嵌套表格. 对已有表格添加行或者列 复制已有表格中的指定行或者列 对跨页的表格可设置是否禁止跨页断行 创建表 ...
- c#操作word表格
http://www.webshu.net/jiaocheng/programme/ASPNET/200804/6499.html <% if request("infoid" ...
- Delphi 操作word 表格
var wordApp, WordDoc, WrdSelection, wrdtable: variant; strAdd: string; wdPar,wdRange:OleVariant; iCo ...
- Aspose.Word 操作word表格的行 插入行 添加行
rows.insert或rows.add前row必须有单元格cell private void button3_Click(object sender, EventArgs e) { ...
- Aspose.Words.Tables.Row类操作word表格行
http://www.aspose.com/docs/display/wordsnet/Aspose.Words.Tables.Row+Class Retrieves the index of a r ...
- 黄聪:jquery.bootgrid表格插件有的属性(visibleInSelection、cssClass、headerCssClass、headerAlign)不能识别的解决办法
主要是属性大小写问题,修改jquery.bootgrid.js文件,在function loadColumns()方法里面添加下面的语句就好了 data.headerAlign = data.head ...
- poi操作word文档文件操作
import org.apache.poi.POITextExtractor; import org.apache.poi.hwpf.extractor.WordExtractor; //得到.doc ...
随机推荐
- python讲一个列表写入excel表中
连接为http://blog.csdn.net/a491057947/article/details/47614263 http://www.crifan.com/export_data_to_exc ...
- jsoup 简介
Java 程序在解析 HTML 文档时,相信大家都接触过 htmlparser 这个开源项目,我曾经在 IBM DW 上发表过两篇关于 htmlparser 的文章,分别是:从HTML中攫取你所需的信 ...
- find_first_of()和 find_last_of() 【获取路径、文件名】
find_first_of()和 find_last_of() [获取路径.文件名](2011-06-11 12:44:46)转载▼标签: 杂谈 分类: c string 类提供字符串处理函数,利用 ...
- 2016 - 1- 23 iOS中xml解析 (!!!!!!!有坑要解决!!!!!!)
一: iOS中xml解析的几种方式简介 1.官方原生 NSXMLParser :SAX方式解析,使用起来比较简单 2.第三方框架 libxml2 :纯C 同时支持DOM与SAX GDataXML: D ...
- 团队开发——冲刺1.e
冲刺阶段一(第五天) 冲刺阶段一(第五天) 1.昨天做了什么?优化界面细节. 查看C#资料,再解决自己电脑的问题. 2.今天准备做什么? 为解决自己电脑的问题,查找关于C#的资料,后期做准备.
- php大力力 [043节] 现在要做个删除前的提示功能
php大力力 [043节] 现在要做个删除前的提示功能
- 传智博客.NET培训第13季 Ajax教程(共十三季) 学习资源
http://wangpengnimei.ctfile.com/u/1235801/47146 传智博客.NET培训第13季 Ajax教程(十三季).rar 19
- 【转】谈谈Google Polymer以及Web UI框架的未来
原文转自:http://www.csdn.net/article/2013-05-27/2815450-google-polymer 摘要:开发者Axel Rauschmayer在自己的博客上详解了G ...
- day11_API第一天
1.Eclipse常用操作 1:安装 A:解压 B:复制到指定的目录(不要有中文,和其他非法字符) 2:使用 A:打开软件的界面 B:新建一个项目(工程) C:在 ...
- Java-->服务器的响应(Servlet--doGet&doPost)
--> Servelet: 用于接收请求(客户端,浏览器),做出响应的,服务器端的,java类 --> ServletLogin -- Web项目服务器响应的Java实现 package ...