使用C#實(shí)現(xiàn)在word中插入頁眉頁腳的方法
針對(duì)Word的操作是很多程序都具備的功能,本文即以實(shí)例展示使用C#實(shí)現(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; }
希望本文實(shí)例能夠?qū)Υ蠹业腃#程序設(shè)計(jì)起到一定的幫助作用。
- C# WORD操作實(shí)現(xiàn)代碼
- C#實(shí)現(xiàn)通過模板自動(dòng)創(chuàng)建Word文檔的方法
- C# Word 類庫的深入理解
- asp.net(c#)下讀取word文檔的方法小結(jié)
- 比較全的一個(gè)C#操作word文檔示例
- 使用c#在word文檔中創(chuàng)建表格的方法詳解
- c#開發(fā)word批量轉(zhuǎn)pdf源碼分享
- C#采用OpenXml實(shí)現(xiàn)給word文檔添加文字
- C#采用OpenXml給word里面插入圖片
- C#實(shí)現(xiàn)合并多個(gè)word文檔的方法
- C#獲取Word文檔中所有表格的實(shí)現(xiàn)代碼分享
- C#操作word的方法示例
相關(guān)文章
C#使用ScrapySharp快速從網(wǎng)頁采集數(shù)據(jù)
這篇文章介紹了使用ScrapySharp快速從網(wǎng)頁采集數(shù)據(jù)的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06C#單例模式Singleton的實(shí)現(xiàn)詳解
單例模式(Singleton?Pattern)是日常開發(fā)中最簡單的設(shè)計(jì)模式之一,它提供了一種創(chuàng)建對(duì)象的最佳方式,本文主要為大家介紹的是C#單例模式的實(shí)現(xiàn)方法,需要的可以參考一下2023-05-05C# KeyUp事件中MessageBox的回車(Enter)鍵回調(diào)問題解決方案
這篇文章主要介紹了C# KeyUp事件中MessageBox的回車(Enter)鍵回調(diào)問題解決方案,需要的朋友可以參考下2014-07-07C#實(shí)現(xiàn)從多列的DataTable里取需要的幾列
這篇文章主要介紹了C#實(shí)現(xiàn)從多列的DataTable里取需要的幾列,涉及C#針對(duì)DataTable操作的相關(guān)技巧,需要的朋友可以參考下2016-03-03C#調(diào)用SQL?Server中有參數(shù)的存儲(chǔ)過程
這篇文章介紹了C#調(diào)用SQL?Server中有參數(shù)存儲(chǔ)過程的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03C# WinForm控件對(duì)透明圖片重疊時(shí)出現(xiàn)圖片不透明的簡單解決方法
這篇文章主要介紹了C# WinForm控件對(duì)透明圖片重疊時(shí)出現(xiàn)圖片不透明的簡單解決方法,結(jié)合實(shí)例形式分析了WinForm圖片重疊后造成圖片不透明的原因與相應(yīng)的解決方法,需要的朋友可以參考下2016-06-06