-
Notifications
You must be signed in to change notification settings - Fork 599
word instrtext
goworm edited this page Jun 26, 2026
·
1 revision
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])
- 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
addis intentionally not supported — aninstrTextoutside a field is invalid. Use--type fieldto insert a complete field sequence.
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. |
| Attribute | Type | Description |
|---|---|---|
instruction |
string | The instrText element text content |
# 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]"-
setrewrites a field's instruction (e.g.PAGE→DATE) without touching the surroundingfldCharmarkers, which makes it suited to audit → fix workflows. - Leading and trailing spaces inside the
instructionvalue are significant: they form the OOXML separator between switches, so keep them as shown in the examples.
-
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