使用C#實現(xiàn)在word中插入頁眉頁腳的方法
針對Word的操作是很多程序都具備的功能,本文即以實例展示使用C#實現(xiàn)在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);
//跳出頁眉頁腳設(shè)置
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;
}
希望本文實例能夠?qū)Υ蠹业腃#程序設(shè)計起到一定的幫助作用。
相關(guān)文章
C#使用ScrapySharp快速從網(wǎng)頁采集數(shù)據(jù)
這篇文章介紹了使用ScrapySharp快速從網(wǎng)頁采集數(shù)據(jù)的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06
C# KeyUp事件中MessageBox的回車(Enter)鍵回調(diào)問題解決方案
這篇文章主要介紹了C# KeyUp事件中MessageBox的回車(Enter)鍵回調(diào)問題解決方案,需要的朋友可以參考下2014-07-07
C#實現(xiàn)從多列的DataTable里取需要的幾列
這篇文章主要介紹了C#實現(xiàn)從多列的DataTable里取需要的幾列,涉及C#針對DataTable操作的相關(guān)技巧,需要的朋友可以參考下2016-03-03
C#調(diào)用SQL?Server中有參數(shù)的存儲過程
這篇文章介紹了C#調(diào)用SQL?Server中有參數(shù)存儲過程的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03
C# WinForm控件對透明圖片重疊時出現(xiàn)圖片不透明的簡單解決方法
這篇文章主要介紹了C# WinForm控件對透明圖片重疊時出現(xiàn)圖片不透明的簡單解決方法,結(jié)合實例形式分析了WinForm圖片重疊后造成圖片不透明的原因與相應(yīng)的解決方法,需要的朋友可以參考下2016-06-06

