博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vsto-Word相关操作
阅读量:5110 次
发布时间:2019-06-13

本文共 4446 字,大约阅读时间需要 14 分钟。

//添加页码到页脚Document doc = Globals.ThisAddIn.Application.ActiveDocument;HeaderFooter hprimary= doc.Sections[1].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[1].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);  //分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[1];  //获取当前文档中第一个图形对象InlineShape igs = Globals.ThisAddIn.Application.ActiveDocument.InlineShapes[1];  //获取当前文档中第一个图片对象InlineShape idfs= range.InlineShapes[1];   //获取指定区域中第一个图片对象idfs.Range.Select();          Shape sr = range.ShapeRange[1];    //获取指定区域中第一个图形对象
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 = 40;        ils.ScaleWidth = 40;      }    }  }}

 

 

 

//Table的相关操作Table t=range.Tables.Add(range,2,2);t.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleThickThinLargeGap;  ////设置Table的外边框线格式t.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;foreach (Row item in t.Rows){     item.Height = 32;     //设置行高     Range rowRange = item.Cells [1].Range;     Table rowT = rowRange.Tables.Add(rowRange, 1, 17);   //嵌套Table     rowT.Rows.Height = 24;     rowT.Columns.Width = 24;    //设置列宽     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(1,1).Range.Text="Test";   //下标都是从1开始//单元格中文本格式比较复杂的可以作为段落 Paragraph pTitle = t.Cell(2, 1).Range.Paragraphs.Add(t.Cell(1, 1).Range);            pTitle.Range.Font.Size = 24;pTitle.Range.Text = "这里是标题";pTitle.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;   //设置水平居中

 

 

转载于:https://www.cnblogs.com/Betty-IT/p/9072725.html

你可能感兴趣的文章
myeclipse插件安装
查看>>
浙江省第十二届省赛 Beauty of Array(思维题)
查看>>
NOIP2013 提高组 Day1
查看>>
个人对vue生命周期的理解
查看>>
cocos2dx 3.x simpleAudioEngine 长音效被众多短音效打断问题
查看>>
存储(硬件方面的一些基本术语)
查看>>
观察者模式
查看>>
转】MyEclipse使用总结——MyEclipse文件查找技巧
查看>>
Weka中数据挖掘与机器学习系列之基本概念(三)
查看>>
Win磁盘MBR转换为GUID
查看>>
大家在做.NET B/S项目的时候多用什么设技术啊?
查看>>
Java SE和Java EE应用的性能调优
查看>>
Android设计模式系列--原型模式
查看>>
免费的论文查重网站
查看>>
C语言程序第一次作业
查看>>
leetcode-Sort List
查看>>
phpcms
查看>>
中文词频统计
查看>>
[.net 面向对象编程基础] (19) LINQ基础
查看>>
Win10 虚拟桌面
查看>>