//LineSpacingRule设置段落的行间距类型,值为枚举字典表
word.Selection.ParagraphFormat.LineSpacingRule = 4;
// LineSpacing间距,单位磅,当LineSpacingRule为5时,值为行数
word.Selection.ParagraphFormat.LineSpacing = 5;
word.Selection.ParagraphFormat.Alignment = 2;
word.Selection.Font.Size = 16;
word.Selection.Font.Name = "仿宋_GB2312";
word.Selection.ClearFormatting();
// 插入括号内的内容,可以是变量,会应用ClearFormatting之前设置的格式
word.Selection.TypeText("内容");
word.Selection.InlineShapes.AddPicture('${url}/static/image/heb/国土党组呈.png');
换行word.Selection.TypeParagraph();
// RelativeHorizontalPosition和RelativeVerticalPosition是设置浮动图片的位置,是相对于什么部分,值对应枚举字典表
var shpPic = word.ActiveDocument.Shapes.AddPicture('${url}/static/image/heb/国土函.jpg');
shpPic.RelativeHorizontalPosition = 1;
shpPic.RelativeVerticalPosition = 1;
// RelativeHorizontalPosition和RelativeVerticalPosition和浮动图片的一致
// shpLabel.Line是文本框的边框,Visible = 0是边框不可见
var shpLabel = word.ActiveDocument.Shapes.AddLabel(1, 370, 25, 60, 10);
shpLabel.RelativeHorizontalPosition = 1;
shpLabel.RelativeVerticalPosition = 1;
shpLabel.TextFrame.TextRange.Text = "请示〔" + ${dispatchYear} + "〕XX号";
shpLabel.TextFrame.TextRange.Font.Name = "黑体";
shpLabel.TextFrame.TextRange.Font.Size = 16;
var shpLineFormat = shpLabel.Line;
word.WordBasic.ViewFooterOnly();
word.ActiveDocument.AttachedTemplate.BuildingBlockEntries.Add("PageNumbers", 26, "BookPages", word.Selection.Range);
word.Selection.Range.Fields.Add(word.Selection.Range, -1, "Page", 1);
word.Selection.Range.Fields.Update();
// NumberStyle 设置页码格式为"- 1 -"效果
word.Selection.HeaderFooter.PageNumbers.NumberStyle = 57;
word.Selection.HeaderFooter.PageNumbers.RestartNumberingAtSection = 0;
word.Selection.HeaderFooter.PageNumbers.StartingNumber = 2;
// ShowFirstPageNumber 设置不显示第一页页码
word.Selection.HeaderFooter.PageNumbers.ShowFirstPageNumber = 0;
// 切换到下一个页脚区域,并设置页码居中显示,加try避免只有一页的情况切换报错
word.ActiveDocument.ActiveWindow.ActivePane.View.NextHeaderFooter();
word.Selection.HeaderFooter.PageNumbers.Item(1).Alignment = 1;
word.Selection.HeaderFooter.PageNumbers.StartingNumber = 1;
word.Selection.HeaderFooter.PageNumbers.ShowFirstPageNumber = 1;
word.Selection.HeaderFooter.PageNumbers.Item(1).Alignment = 1;
word.Selection.Range.Font.Size = 14;
word.Selection.Range.Font.Name = "宋体";
word.Selection.Range.ParagraphFormat.Alignment = 1;
word.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = 0;
word.WordBasic.ViewFooterOnly();
// NumberStyle设置编码样式,57是- 1 -样式
word.Selection.HeaderFooter.PageNumbers.NumberStyle = 57;
word.Selection.HeaderFooter.PageNumbers.RestartNumberingAtSection = 0;
// 由于该效果是双页打印,需要设置奇偶页不同,所以会多设置一个页码的效果
word.ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter = -1;
// 控制第一页是否需要页码,1表示第一页不显示页码,0表示第一页显示页码
word.Selection.HeaderFooter.PageNumbers.StartingNumber = 2;
word.Selection.HeaderFooter.PageNumbers.ShowFirstPageNumber = 0;
// 尝试设置第二页和第三页的页码字体、字号、对其方式和左右缩进
// 切换到下一个页脚,进入页脚视图时是在第一页的页脚(切换后当前是第二页)
word.ActiveDocument.ActiveWindow.ActivePane.View.NextHeaderFooter();
word.Selection.Range.Font.Size = 14;
word.Selection.Range.Font.Name = "宋体";
word.Selection.Range.ParagraphFormat.Alignment = 0;
word.Selection.Range.ParagraphFormat.CharacterUnitLeftIndent = 1;
word.Selection.Range.ParagraphFormat.CharacterUnitRightIndent = 1;
word.ActiveDocument.ActiveWindow.ActivePane.View.NextHeaderFooter();
word.Selection.Range.Font.Size = 14;
word.Selection.Range.Font.Name = "宋体";
word.Selection.Range.ParagraphFormat.Alignment = 2;
word.Selection.Range.ParagraphFormat.CharacterUnitLeftIndent = 1;
word.Selection.Range.ParagraphFormat.CharacterUnitRightIndent = 1;
word.Selection.HeaderFooter.PageNumbers.StartingNumber = 1;
word.Selection.HeaderFooter.PageNumbers.ShowFirstPageNumber = 1;
word.Selection.Range.Font.Size = 14;
word.Selection.Range.Font.Name = "宋体";
word.Selection.Range.ParagraphFormat.Alignment = 2;
word.Selection.Range.ParagraphFormat.CharacterUnitLeftIndent = 1;
word.Selection.Range.ParagraphFormat.CharacterUnitRightIndent = 1;
word.ActiveDocument.ActiveWindow.ActivePane.View.NextHeaderFooter();
word.Selection.Range.Font.Size = 14;
word.Selection.Range.Font.Name = "宋体";
word.Selection.Range.ParagraphFormat.Alignment = 0;
word.Selection.Range.ParagraphFormat.CharacterUnitLeftIndent = 1;
word.Selection.Range.ParagraphFormat.CharacterUnitRightIndent = 1;
word.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = 0;