针对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#程序设计起到一定的帮助作用。
除声明外,跑步客文章均为原创,转载请以链接形式标明本文地址使用C#实现在word中插入页眉页脚的方法
本文地址: http://www.paobuke.com/develop/c-develop/pbk23632.html
相关内容
C#七大经典排序算法系列(上)C#给PDF文件添加水印C#实现文件上传与下载功能实例C# DataTable中Compute方法用法集锦(数值/字符串/运算符/表等操作)C#编程自学之数据类型和变量一C#发送数据到剪贴板及从剪贴板中取数据的方法C#自定义序列化ISerializable的实现方法C#中is与as的区别分析