Skip to content

word reference

zmworm edited this page Apr 4, 2026 · 29 revisions

Word (.docx) Reference

Complete reference for OfficeCLI operations on Word documents.

Elements

Element Path Operations
Document / set
Paragraph /body/p[N] add, set
Run /body/p[N]/r[M] add, set
Table /body/tbl[N] add, set
Header/Footer /header[N], /footer[N] add, set
Watermark /watermark add, set
Section /section[N] add, set
Picture (inline/floating) add
Bookmark /bookmark[Name] add, set
Footnote/Endnote /footnote[N], /endnote[N] add, remove
Hyperlink (inline) add
Comment (attached) add
TOC /toc[N] add, remove
Equation (inline/block) add
Style /styles/{StyleId} add, set
Chart /chart[N] add, set, remove
Field (inline) add
Break (inline) add
SDT/Content Control /body/sdt[N] add, set, remove
Form Field /formfield[N] or /formfield[Name] add, set, get

Path Aliases

Human-friendly path names are accepted as aliases:

Alias Short Form Example
paragraph p /body/paragraph[1] = /body/p[1]
run r /body/p[1]/run[1] = /body/p[1]/r[1]
table tbl /body/table[1] = /body/tbl[1]
row tr /body/tbl[1]/row[1] = /body/tbl[1]/tr[1]
cell tc /body/tbl[1]/tr[1]/cell[1] = /body/tbl[1]/tr[1]/tc[1]

Stable Element Addressing

Paragraphs have auto-assigned w14:paraId and w14:textId for stable addressing across edits:

Path Description
/body/p[@paraId=XXXXXXXX] Navigate to paragraph by paraId
/body/p[@textId=XXXXXXXX] Navigate to paragraph by textId
/picture[@id=N] Navigate to picture by docPr ID
/chart[@id=N] Navigate to chart by docPr ID
/comments/c[@commentId=N] Navigate to comment by commentId
/body/sdt[@sdtId=N] Navigate to SDT/content control by sdtId
  • paraId is assigned on creation and preserved across edits
  • textId refreshes when paragraph content changes (set, find-replace, add/remove run)
  • docPr IDs are auto-deduped on open
  • Get output now returns stable ID paths (e.g., p[@paraId=...] instead of p[N])

Track Changes

Accept or reject all tracked changes in a document:

# Accept all changes (apply insertions, remove deletions)
officecli set report.docx / --prop accept-changes=all

# Reject all changes (remove insertions, restore deletions)
officecli set report.docx / --prop reject-changes=all

Handles: insertions, deletions, formatting changes, section/table/paragraph property changes, move markers.

Hyperlink Set

Modify hyperlink target and display text:

officecli set report.docx /body/p[1]/hyperlink[1] --prop url=https://example.com --prop text="Click here"

Properties: url/link/href (target URI), text (display text).

Raw XML Parts

For low-level operations using the raw and raw-set commands:

Part Path Description
/document (default) Main document body XML
/styles Style definitions XML
/numbering List/numbering definitions
/settings Document settings
/header[N] Header XML (0-based for raw)
/footer[N] Footer XML (0-based for raw)

XPath namespace prefixes: w (WordprocessingML), r (Relationships), a (DrawingML), mc (Markup Compatibility), wp (Word Drawing), wps (Word Drawing Shape), v (VML)

# View raw document XML
officecli raw report.docx /document

# Remove all bold from document
officecli raw-set report.docx /document --xpath "//w:b" --action remove

# Set justification via raw XML
officecli raw-set report.docx /document --xpath "//w:pPr/w:jc" --action setattr --xml "w:val=center"

Copy Elements

# Copy a paragraph
officecli add report.docx /body --from /body/p[1]

# Copy a table
officecli add report.docx /body --from /body/tbl[1] --index 0

Based on OfficeCLI v1.0.33

Clone this wiki locally