页眉页脚

WordCreator有两个属性,用于设置页眉和页脚:

属性 说明
Header 返回页眉
Footer 返回页脚

Header和Footer是容器,可以向其中添加任何类型的对象。

以下类型主要用于Header和Footer:

类型 说明
RtfPageField 用于显示页码
RtfNumPagesField 用于显示总页数
RtfTimeField 用于显示当前时间
RtfDateField 用于显示当前日期

示例:

Dim wdc As New WordCreator()
Dim
pgf As New Word.Objects.RtfParagraph() '增加一个段落用于显示页码和页数
pgf.Add(
New Word.Objects.RtfPageField) '增加页码
pgf.Add(
New Word.Objects.RtfString("/")) '增加分隔符
pgf.Add(
New Word.Objects.RtfNumPagesField) '增加总页数
pgf.Alignment = Word.RtfHorizontalAlignment.Right
'段落(页眉)靠右对齐
wdc.Footer.Add(pgf)
'将段落添加页脚中
For
i As Integer = 1 To 5
    wdc.AddParagraph(
"Foxtable 2025春季更新").Alignment = Word.RtfHorizontalAlignment.Left
    wdc.PageBreak
'换页
Next
Dim
fl As String = "c:\temp\test.docx"
wdc.Save(fl)
'保存文件
Process.Start(fl)
'打开文件

执行上述代码后生成的文档,每一页的页眉都会显示页码和总页数:


本页地址:http://www.foxtable.com/webhelp/topics/6046.htm