黄聪: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 ...
随机推荐
- mysql常用语句、命令(增删改查功能)
修改数据库的字符集 mysql>use mydb mysql>alter database mydb character set utf8;创建数据库指定数据库的字符集 ...
- 使用 IN 的子查询
通过 IN(或 NOT IN)引入的子查询结果是一列零值或更多值.子查询返回结果之后,外部查询将利用这些结果. 下列查询会找到所有曾出版过商业书籍的出版商的名称. USE pubs SELECT pu ...
- 在Ubuntu上安装JDK、Ant、Jmeter和Jenkins
一.前期准备 1. 在win7下载VMware.Ubuntu(用迅雷下比较快) 2. 安装完VMware后新建虚拟机,选择iso: 3. 具体配置参考如下,至此Ubantu安装完成 二.在Ubuntu ...
- DeepLearning之路(三)MLP
DeepLearning tutorial(3)MLP多层感知机原理简介+代码详解 @author:wepon @blog:http://blog.csdn.net/u012162613/articl ...
- C++ STL算法系列2---find ,find_first_of , find_if , adjacent_find的使用
一.find运算 假设有一个int型的vector对象,名为vec,我们想知道其中是否包含某个特定值. 解决这个问题最简单的方法时使用标准库提供的find运算: 1 // value we'll lo ...
- candence 知识积累2
1 Allegro Symbol的类型以及作用: (1)Package Symbol : PCB里的封装符号,元器件的footprint,用来做元器件的封装,后缀(.psm),主要在电器层Etch ( ...
- Introducing Windows 10 Editions(Windows10版本介绍)
Windows 10将在今年夏天正式发布,今天微软官方博客分享了一些Windows 10版本的细节.详见Introducing Windows 10 Editions Windows 10 HomeW ...
- zlhome.com Deal
using AnfleCrawler.Common; using System; using System.Collections.Generic; using System.Linq; using ...
- Python的平凡之路(11)
一. rabbitmq 1 进程Queue: 父进程与子进程进行交互,或者同属于同一父进程下多个子进程进行交互 2 队列通信: send1.py #!/usr/bin/env python#Au ...
- UVa 1626 Brackets sequence (动态规划)
题意:用最少的括号将给定的字符串匹配,输出最优解.可能有空行. 思路:dp. dp[i][j]表示将区间i,j之间的字符串匹配需要的最少括号数,那么 如果区间左边是(或[,表示可以和右边的字符串匹配, ...