使用C#在word中插入页眉页脚

//插入页脚

  1. public void InsertFooter(string footer)
  2. {
  3. if (ActiveWindow.ActivePane.View.Type == WdViewType.wdNormalView ||
  4. ActiveWindow.ActivePane.View.Type == WdViewType.wdOutlineView)
  5. {
  6. ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView;
  7. }
  8. ActiveWindow.View.SeekView = WdSeekView.wdSeekCurrentPageFooter;
  9. this.Application.Selection.HeaderFooter.LinkToPrevious = false;
  10. this.Application.Selection.HeaderFooter.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
  11. ActiveWindow.ActivePane.Selection.InsertAfter(footer);
  12. //跳出页眉页脚设置
  13. ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;
  14. }

msdn上的方法

    1. foreach (Word.Section wordSection in this.Application.ActiveDocument.Sections)
    2. {
    3. Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
    4. footerRange.Font.ColorIndex = Word.WdColorIndex.wdDarkRed;
    5. footerRange.Font.Size = 20;
    6. footerRange.Text = "页脚 页脚";
    7. }
    8. foreach (Word.Section section in this.Application.ActiveDocument.Sections)
    9. {
    10. Word.Range headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
    11. headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage);
    12. headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
    13. }
上一篇:[Ruby on Rails系列]5、专题:Talk About SaSS


下一篇:Ruby多字节字符的设计