Skip to content

word header footer

zmworm edited this page Apr 29, 2026 · 53 revisions

Word: Header and Footer

Page headers and footers with support for default, first-page, and even-page variants. Each header/footer is stored as a separate part in the document package, referenced by section properties.

Path: /header[N], /footer[N]

Operations

  • add - Add headers and footers
  • set - Modify header/footer content and formatting

Type variants

Type Description Prerequisite
default Appears on all pages (or odd pages when even/odd is enabled) None
first Appears on the first page only Automatically enables titlePage in section properties
even Appears on even-numbered pages Requires evenAndOddHeaders=true on document settings

When you add a type=first header or footer, OfficeCLI automatically sets the <w:titlePage> element on the section. For even-page headers/footers, set evenAndOddHeaders on the document first:

officecli set report.docx /settings --prop evenAndOddHeaders=true
officecli add report.docx / --type header --prop text="Even Page Header" --prop type=even

Format properties (returned by get)

Key Type Description
type default, first, even Header/footer type from section reference
alignment string First paragraph justification (left, center, right, justify)
font string First run font family
size string First run font size (e.g., 11pt)
bold bool First run bold
italic bool First run italic
color string First run color (#FF0000 or theme name)
underline string First run underline style
strike bool First run strikethrough
highlight string First run highlight color

Child paragraphs are accessible at /header[N]/p[K] (or /header[N]/p[@paraId=...]) and support the full paragraph property set.

get

officecli get report.docx /header[1]
officecli get report.docx /footer[1]

# Deep get — includes child paragraphs and runs
officecli get report.docx /header[1] --depth 2

query

# List all headers
officecli query report.docx "header"

# List all footers
officecli query report.docx "footer"

remove

Removing a header/footer deletes the part and cleans up all section references and orphaned image parts.

officecli remove report.docx /header[1]
officecli remove report.docx /footer[1]

Adding content inside headers/footers

After creating a header or footer, you can add paragraphs, pictures, and other elements inside it:

# Add a paragraph to an existing header
officecli add report.docx /header[1] --type paragraph --prop text="Additional line" --prop alignment=right

# Add a picture to a footer
officecli add report.docx /footer[1] --type picture --prop src=logo.png --prop width=2cm

Document settings related to headers/footers

Set via officecli set <file> /settings --prop <key>=<value>:

Setting Description
evenAndOddHeaders Enable different headers/footers for even and odd pages

The titlePage flag is managed automatically when adding type=first headers/footers.


Based on OfficeCLI v1.0.64

Clone this wiki locally