Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

command add word

zmworm edited this page Apr 4, 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 "天气" in paragraph 1
officecli add doc.docx '/body/p[1]' --type run --after find:天气 --prop text=(晴)
# Insert a run before the text "天气"
officecli add doc.docx '/body/p[1]' --type run --before find:天气 --prop text=【
# Insert a table after a sentence (splits the paragraph)
officecli add doc.docx '/body/p[1]' --type table --after find:第一句话。 --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=(新高)

See Also


Based on OfficeCLI v1.0.33

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /