大学IT网 - 最懂大学生的IT学习网站! QQ资料交流群:367606806
当前位置:大学IT网 > C#技巧 > 使用C#在word中插入页眉页脚

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

关键词:word插入页眉页脚C#  阅读(882) 赞(14)

[摘要]本文是对使用C#在word中插入页眉页脚的讲解,对学习C#编程技术有所帮助,与大家分享。

//插入页脚

[csharp]view plaincopyprint?
  1. publicvoidInsertFooter(stringfooter)
  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上的方法

[csharp]view plaincopyprint?
    1. foreach(Word.SectionwordSectioninthis.Application.ActiveDocument.Sections)
    2. {
    3. Word.RangefooterRange=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.Sectionsectioninthis.Application.ActiveDocument.Sections)
    9. {
    10. Word.RangeheaderRange=section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
    11. headerRange.Fields.Add(headerRange,Word.WdFieldType.wdFieldPage);
    12. headerRange.ParagraphFormat.Alignment=Word.WdParagraphAlignment.wdAlignParagraphRight;
    13. }


相关评论