Skip to content
本页内容

页眉/页脚(HeadersFooters)

文档中的所有页眉页脚,可通过 ActiveDocument.Sections.Item(Index).HeadersActiveDocument.Sections.Item(Index).Footers 返回 HeadersFooters 对象

语法

表达式.ActiveDocument.Sections.Item(Index).Headers

或者 表达式.ActiveDocument.Sections.Item(Index).Footers

表达式:文档类型应用对象

参数

属性数据类型默认值必填说明
Type
Enum
-
指定返回的页眉/页脚类型。为 1 (WdHeaderFooterIndex.wdHeaderFooterPrimary)表示返回文档或节中除第一页外所有页上的页眉或页脚

返回值

返回 HeadersFooters 对象

示例

js
//@file=base.docx
async function example() {
  await instance.ready()

  const app = instance.Application

  // 获取页眉文本
  const HeanderText = await app.ActiveDocument.Sections.Item(1).Headers(1).Range
    .Text

  // 获取页脚文本
  const FooterText = await app.ActiveDocument.Sections.Item(1).Footers(1).Range
    .Text
}

属性列表

属性说明
返回一个 Range 对象, 该对象代表指定对象中包含的文档部分

Range

返回一个 Range 对象, 该对象代表指定对象中包含的文档部分

语法

表达式.ActiveDocument.Sections.Item(Index).Headers.Range

或者 表达式.ActiveDocument.Sections.Item(Index).Footers.Range

表达式:文档类型应用对象

示例

js
//@file=base.docx
async function example() {
  await instance.ready()

  const app = instance.Application

  // Range 对象
  const Range = await app.ActiveDocument.Sections.Item(1).Headers(1).Range
}