• 使用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.   
    9.     ActiveWindow.View.SeekView = WdSeekView.wdSeekCurrentPageFooter;  
    10.     this.Application.Selection.HeaderFooter.LinkToPrevious = false;  
    11.     this.Application.Selection.HeaderFooter.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;  
    12.     ActiveWindow.ActivePane.Selection.InsertAfter(footer);  
    13.   
    14.     //跳出页眉页脚设置  
    15.     ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;  
    16.   
    17. }  


     

    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.   
      9.            foreach (Word.Section section in this.Application.ActiveDocument.Sections)  
      10.            {  
      11.                Word.Range headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;  
      12.                headerRange.Fields.Add(headerRange, Word.WdFieldType.wdFieldPage);  
      13.                headerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;  
      14.            } 
  • 相关阅读:
    DevExpress-xaml常用控件
    循环中Random()产生相同随机数问题的对策
    插入U盘提示程序
    钛度TSG309鼠,血手幽灵P93 彩漫鼠,微星GM41Lightweight鼠标参数对比
    MarkdownPad
    C# 通过路径取文件方法
    初识张首晟教授有感
    【机器学习123】模型评估与选择 (上)
    【机器学习123】绪论
    【深度学习123】开篇
  • 原文地址:https://www.cnblogs.com/rr163/p/3922349.html
Copyright © 2020-2023  润新知