public bool InsertPageFooterNumber(System.Drawing.Font font, WordPlayer.Alignment alignment) { try { oWord.ActiveWindow.View.SeekView = WdSeekView.wdSeekCurrentPageHeader; oWord.Selection.WholeStory(); oWord.Selection.ParagraphFormat.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleNone; oWord.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekMainDocument; oWord.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekCurrentPageFooter;//页脚 oWord.Selection.TypeText("第"); object page = WdFieldType.wdFieldPage; oWord.Selection.Fields.Add(oWord.Selection.Range, ref page, ref Nothing, ref Nothing); oWord.Selection.TypeText("页/共"); object pages = WdFieldType.wdFieldNumPages; oWord.Selection.Fields.Add(oWord.Selection.Range, ref pages, ref Nothing, ref Nothing); oWord.Selection.TypeText("页"); GetWordFont(oWord.Selection.Font, font); SetAlignment(oWord.Selection.Range, alignment); oWord.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekMainDocument; return true; } catch (Exception) { return false; } }
/// <summary> /// 插入页脚 /// </summary> /// <param name="text"></param> /// <param name="font"></param> /// <param name="alignment"></param> /// <returns></returns> public bool InsertPageFooter(string text, System.Drawing.Font font, WordPlayer.Alignment alignment) { try { oWord.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekCurrentPageFooter;//页脚 oWord.Selection.InsertAfter(text); GetWordFont(oWord.Selection.Font, font); SetAlignment(oWord.Selection.Range, alignment); return true; } catch (Exception) { return false; } }