本文即以实例展示使用C#实现在word中插入页眉页脚的方法

时间:2022-04-03 08:39:47

针对Word的操纵是很多措施都具备的成果,本文即以实例展示使用C#实此刻word中插入页眉页脚的要领,,供大家参考借鉴,具体要领如下:


一、插入页脚的要领:

public void InsertFooter(string footer) { if (ActiveWindow.ActivePane.View.Type == WdViewType.wdNormalView || ActiveWindow.ActivePane.View.Type == WdViewType.wdOutlineView) { ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView; } ActiveWindow.View.SeekView = WdSeekView.wdSeekCurrentPageFooter; this.Application.Selection.HeaderFooter.LinkToPrevious = false; this.Application.Selection.HeaderFooter.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; ActiveWindow.ActivePane.Selection.InsertAfter(footer); //跳出页眉页脚设置 ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; }


二、msdn上的要领:

foreach (Word.Section wordSection in this.Application.ActiveDocument.Sections) { Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; footerRange.Font.ColorIndex = Word.WdColorIndex.wdDarkRed; footerRange.Font.Size = 20; footerRange.Text = "页脚 页脚"; } foreach (Word.Section section in this.Application.ActiveDocument.Sections) { Word.Range headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage); headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; }

但愿本文实例能够对大家的C#措施设计起到必然的辅佐感化。

除声明外,跑步客文章均为原创,转载请以链接形式标明本文地点
  

本文地点: