Skip to content

command add word

zmworm edited this page Apr 9, 2026 · 53 revisions

add - Word (.docx)

Addable element types in Word documents.

Element Types

Type Aliases Parent Reference
paragraph p /body, headers, cells Word-Paragraph-Add
run r /body/p[N] Word-Run-Add
table tbl /body Word-Table-Add
row tr /body/tbl[N] Word-Table-Add
cell tc /body/tbl[N]/tr[M] Word-Table-Add
picture image, img /body, /body/p[N] Word-Picture-Add
chart - /body Word-Chart-Add
equation formula, math /body, /body/p[N] Word-Equation-Add
hyperlink link /body/p[N] Word-Hyperlink-Add
comment - /body/p[N] Word-Comment-Add
bookmark - /body/p[N] Word-Bookmark-Add
section sectionBreak /body Word-Section-Add
footnote - /body/p[N] Word-Footnote-Add
endnote - /body/p[N] Word-Footnote-Add
toc tableOfContents /body Word-TOC-Add
header - / Word-Header-Footer-Add
footer - / Word-Header-Footer-Add
watermark - / Word-Watermark-Add
style - /styles Word-Style-Add
field pagenum, pagenumber, numpages, date /body/p[N], /body Word-Field-Add
pagebreak/break columnbreak /body/p[N], /body Word-Break-Add
sdt contentcontrol /body, /body/p[N] Word-SDT-Add
formfield ff /body Word-FormField

Position by DOM Path

Use --after or --before with a DOM path to insert relative to a sibling:

# Insert a paragraph after the 2nd paragraph
officecli add doc.docx /body --type paragraph --after /body/p[2] --prop text="Inserted"

# Insert a paragraph before the first table
officecli add doc.docx /body --type paragraph --before /body/tbl[1] --prop text="Table intro"

Text-Anchored Insert with --after find:X / --before find:X

Insert elements at a text-matched position within a paragraph. Use --after find:X or --before find:X to locate the insertion point by matching text content.

  • Inline types (run, image, hyperlink, bookmark, field) are inserted within the paragraph, adjacent to the matched text.
  • Block types (table, paragraph, section, break) cause the paragraph to split at the match point; the new block element is inserted between the resulting halves.
  • Add --prop regex=true for regex matching.

Examples

# Insert a run after the text "weather" in paragraph 1
officecli add doc.docx '/body/p[1]' --type run --after find:weather --prop "text= (sunny)"

# Insert a run before the text "weather"
officecli add doc.docx '/body/p[1]' --type run --before find:weather --prop "text=["

# Insert a table after a sentence (splits the paragraph)
officecli add doc.docx '/body/p[1]' --type table --after "find:first sentence." --prop rows=2 --prop cols=2

# Regex: insert after the first number sequence
officecli add doc.docx '/body/p[1]' --type run --after 'find:\d+' --prop regex=true --prop "text= (new high)"

See Also


Based on OfficeCLI v1.0.40

Clone this wiki locally