Skip to content

word instrtext

goworm edited this page Jun 26, 2026 · 1 revision

Word: Field Instruction Text

Field-instruction text (w:instrText) — the body of a complex field that holds the instruction string, such as PAGE \* MERGEFORMAT or DATE \@ "yyyy-MM-dd".

Path: /body/p[@paraId=X]/r[N] (also /header[N]/p[M]/r[K] and /footer[N]/p[M]/r[K])

Operations

  • set - Rewrite a field's instruction string in place
  • get - Read the current instruction text
  • query - Find instrText elements
  • remove - Delete the instruction text

Atomic add is intentionally not supported — an instrText outside a field is invalid. Use --type field to insert a complete field sequence.

set

Parent: paragraph

Property Required/Default Description
instruction (alias instr) required The Word field instruction. Leading/trailing spaces inside the value are significant — they form the OOXML separator between switches.

get Attributes

Attribute Type Description
instruction string The instrText element text content

Examples

# Rewrite a field's instruction to a PAGE field with MERGEFORMAT
officecli set report.docx "/body/p[@paraId=12AB34CD]/r[2]" --type instrText \
  --prop 'instruction= PAGE \* MERGEFORMAT '

# Rewrite to a formatted DATE field (alias: instr)
officecli set report.docx "/body/p[@paraId=12AB34CD]/r[2]" --type instrText \
  --prop 'instr= DATE \@ "yyyy-MM-dd" '

# Read the current instruction text
officecli get report.docx "/body/p[@paraId=12AB34CD]/r[2]"

# Find all instruction-text elements
officecli query report.docx instrText

# Remove an instruction-text run
officecli remove report.docx "/body/p[@paraId=12AB34CD]/r[2]"

Notes

  • set rewrites a field's instruction (e.g. PAGEDATE) without touching the surrounding fldChar markers, which makes it suited to audit → fix workflows.
  • Leading and trailing spaces inside the instruction value are significant: they form the OOXML separator between switches, so keep them as shown in the examples.

See Also

  • Field - Insert complete field sequences with --type field
  • Run - The run that contains the instruction text
  • Paragraph - Parent element
  • Word Reference - All Word elements

Based on OfficeCLI v1.0.119

Clone this wiki locally