vsto-Word相关操作
//添加页码到页脚
Document doc = Globals.ThisAddIn.Application.ActiveDocument;
HeaderFooter hprimary= doc.Sections[].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary];
hprimary.Range.Fields.Add(hprimary.Range, WdFieldType.wdFieldPage);
//添加页脚并显示页码
Document doc = Globals.ThisAddIn.Application.ActiveDocument;
Window activeWindow = doc.Application.ActiveWindow;
object currentPage = WdFieldType.wdFieldPage;
object totalPages = WdFieldType.wdFieldNumPages; // Go to the Footer view
activeWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageFooter;
// Right-align the current selection
activeWindow.ActivePane.Selection.Paragraphs.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter; // Type the page number in 'Page X of Y' format
activeWindow.Selection.TypeText("第 ");
activeWindow.Selection.Fields.Add(
activeWindow.Selection.Range, ref currentPage);
activeWindow.Selection.TypeText("页,共 ");
activeWindow.Selection.Fields.Add(
activeWindow.Selection.Range, ref totalPages);
activeWindow.Selection.TypeText("页 "); //清除页眉横线(不知道为什么页眉会多一条横线)
doc.Sections[].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Borders[WdBorderType.wdBorderBottom].LineStyle =WdLineStyle.wdLineStyleNone;
// Go back to the Main Document view
activeWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument;
//页面配置
PageSetup PAGE = doc.PageSetup;
PAGE.PaperSize = WdPaperSize.wdPaperA3; //A3纸
PAGE.Orientation = WdOrientation.wdOrientLandscape; //横向
PAGE.TextColumns.SetCount(); //分3栏
//定位选中内容的下一行进行操作
Selection sel = Globals.ThisAddIn.Application.Selection; //获取选中内容
sel.InsertParagraph(); //插入新的段落行
Range range = sel.GoToNext(WdGoToItem.wdGoToLine); //定位到新的段落行
range.Text="当前行下一行进行编辑";
//获取指定区域中的文本、图片、图形
Document doc = Globals.ThisAddIn.Application.ActiveDocument;
Range r = doc.Range();
Range range = doc.Range(r.Bookmarks["bookmark1"].Start, r.Bookmarks["bookmark2"].Start);
string text = range.Text; //获取指定区域中的文本内容
//int c = Globals.ThisAddIn.Application.ActiveDocument.Shapes.Count;
Shape s = Globals.ThisAddIn.Application.ActiveDocument.Shapes[]; //获取当前文档中第一个图形对象
InlineShape igs = Globals.ThisAddIn.Application.ActiveDocument.InlineShapes[]; //获取当前文档中第一个图片对象
InlineShape idfs= range.InlineShapes[]; //获取指定区域中第一个图片对象
idfs.Range.Select();
Shape sr = range.ShapeRange[]; //获取指定区域中第一个图形对象
internal void GetImagesInDocument()
{
// iterate through each shape
foreach (InlineShape ils in Globals.ThisAddIn.Application.ActiveDocument.InlineShapes)
{
// validate
if (ils != null)
{
// check if image
if (ils.Type == Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapePicture)
{
// you can do what you want with the object here
ils.ScaleHeight = ;
ils.ScaleWidth = ;
}
}
}
}
//Table的相关操作
Table t=range.Tables.Add(range,,);
t.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleThickThinLargeGap; ////设置Table的外边框线格式
t.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
foreach (Row item in t.Rows)
{
item.Height = ; //设置行高
Range rowRange = item.Cells [].Range;
Table rowT = rowRange.Tables.Add(rowRange, , ); //嵌套Table
rowT.Rows.Height = ;
rowT.Columns.Width = ; //设置列宽
rowT.Borders .OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
rowT.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle;
//rowT.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle; //设置边框顶线
//rowT.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle; //设置边框底线
//rowT.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleSingle;
//rowT.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleSingle;
//rowT.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleSingle; //设置边框内纵线
//rowT.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle; //设置边框内横线
item.Cells.VerticalAlignment =WdCellVerticalAlignment.wdCellAlignVerticalCenter; //设置单元格垂直居中
}
//向单元格添加文本
t.Cell(,).Range.Text="Test"; //下标都是从1开始
//单元格中文本格式比较复杂的可以作为段落
Paragraph pTitle = t.Cell(, ).Range.Paragraphs.Add(t.Cell(, ).Range);
pTitle.Range.Font.Size = ;
pTitle.Range.Text = "这里是标题";
pTitle.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; //设置水平居中
vsto-Word相关操作的更多相关文章
- redis对string进行的相关操作
redis对string类型操作的相关命令以及如何在python使用这些命令 redis对string类型操作的命令: 命令 语法 概述 返回值 Redis SET 命令 set key value ...
- python字符串、字符串处理函数及字符串相关操作
python字符串.字符串处理函数及字符串相关操作 字符串介绍 python字符串表示 Python除处理数字外还可以处理字符串,字符串用单撇号或双撇号包裹: >>> 'spam e ...
- 从零自学Hadoop(20):HBase数据模型相关操作上
阅读目录 序 介绍 命名空间 表 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink 序 ...
- 从零自学Hadoop(21):HBase数据模型相关操作下
阅读目录 序 变量 数据模型操作 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink 序 ...
- 在C#中使用Spire.doc对word的操作总结
在C#中使用Spire.doc对word的操作总结 在最近的工程中我们要处理一些word文档.通过在网上的大量搜索,我发现大多数软件功能不是不完整就是有重复.极少数可以完全实现的word组件又要收费. ...
- 理解CSV文件以及ABAP中的相关操作
在很多ABAP开发中,我们使用CSV文件,有时候,关于CSV文件本身的一些问题使人迷惑.它仅仅是一种被逗号分割的文本文档吗? 让我们先来看看接下来可能要处理的几个相关组件的词汇的语义. Separat ...
- Liunx下的有关于tomcat的相关操作 && Liunx 常用指令
先记录以下liunx下的有关于tomcat的相关操作 查看tomcat进程: ps-ef|grep java (回车) 停止tomcat进程: kill -9 PID (进程号如77447) (回车) ...
- pip的相关操作
>Python中的pip是什么?能够做些什么? pip是Python中的一个进行包管理的东西,能够下载包.安装包.卸载包......一些列操作 >怎么查看pip的相关信息 在控制台输入: ...
- python操作mysql数据库的相关操作实例
python操作mysql数据库的相关操作实例 # -*- coding: utf-8 -*- #python operate mysql database import MySQLdb #数据库名称 ...
随机推荐
- centos7中安装、配置jdk(转载)
参考命令:http://www.jb51.net/os/RedHat/73016.html来进行安装 安装说明 系统环境:centos7安装方式:rpm安装软件:jdk-8u25-linux-x64. ...
- st2_057
http://vulapps.evalbug.com/s_struts2_s2-057/ 这大概是全网复现st2-057环境最简单的操作了. 不过首先,你需要安装过docker,安装方法参考官方文档h ...
- Gitlab安装以及汉化
Gitlab安装以及汉化 系统环境: CentOS 7.5 IP:192.168.1.2 关闭selinux.firewalld gitlab-ce-10.8.4 rpm包:下载地址 一.下载并安装g ...
- QT使用MSVC编译器输出中文乱码问题解决方法
方法一:使用QStringLiteral()宏对每个中文字符串封装,此方法的缺点是不能在使用tr()函数用于字符串翻译: 方法二:强制MSVC编译器采用UTF-8编码生成可执行文件,需要在出现中文字符 ...
- Linux configure,make,make install
https://www.cnblogs.com/tinywan/p/7230039.html https://www.sohu.com/a/191735643_505857 https://blog. ...
- php window系统 xdebug+phpstorm 本地断点调试使用教程
运行环境: phpStorm 2017.2 PHP 7.1.5 Xdebug 2.6.1 php.ini添加xdebug模块 你需要仔细分析和选择要下载的对应版本,否则无法调试.由于非常容易出错,建议 ...
- shell爬虫--抓取某在线文档所有页面
在线教程一般像流水线一样,页面有上一页下一页的按钮,因此,可以利用shell写一个爬虫读取下一页链接地址,配合wget将教程所有内容抓取. 以postgresql中文网为例.下面是实例代码 #!/bi ...
- MySql 三大知识点,索引、锁、事务,原理分析
1.索引 索引,类似书籍的目录,可以根据目录的某个页码立即找到对应的内容. 索引的优点:1. 天生排序,2. 快速查找. 索引的缺点:1. 占用空间,2. 降低更新表的速度. 注意点:小表使用全表扫描 ...
- dataguard从库数据库丢失恢复例子(模拟所有的控制文件)
1.退出日志应用模式[oracle@localhost ~]$ sqlplus /nolog SQL*Plus: Release 11.2.0.4.0 Production on Mon Jan 14 ...
- 剑指offer(59)按之字形顺序打印二叉树
题目描述 请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推. 题目分析 这道题还是需要画图分析,不然不好找 ...