使用C#实现在word中插入页眉页脚的方法
程序员文章站
2023-12-17 21:50:10
针对word的操作是很多程序都具备的功能,本文即以实例展示使用c#实现在word中插入页眉页脚的方法,供大家参考借鉴,具体方法如下:
一、插入页脚的方法:
pu...
针对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#程序设计起到一定的帮助作用。