website/docs/user-guide/skills/bundled/productivity/productivity-docx.md
Create, read, edit, and template Word .docx files.
| Source | Bundled (installed by default) |
| Path | skills/productivity/docx |
| Version | 1.0.0 |
| Author | Nous Research |
| License | MIT |
| Platforms | linux, macos, windows |
| Tags | word, docx, documents, office, templates |
| Related skills | pdf, xlsx, powerpoint |
:::info The following is the complete skill definition that Hermes loads when this skill is triggered. This is what the agent sees as instructions when the skill is active. :::
Create, read, edit, and template Microsoft Word .docx files with
python-docx via four small CLIs. It handles text, styles, lists, tables,
images, headers/footers, and {{token}} templating. It does not render
documents to PDF, edit legacy .doc binaries, or accept/reject tracked
changes (it only detects them — see Pitfalls).
.docx..docx: replace text, edit table cells,
insert/delete paragraphs, apply styles..docx template with {{placeholders}} to fill from data..doc (legacy), .odt, PDF conversion, or WYSIWYG layout work.python-docx installed:
pip install python-docx (import name is docx).All helpers live in scripts/ next to this file. Run them with the
terminal tool; each supports --help and prints JSON to stdout.
python scripts/docx_create.py spec.json out.docx
python scripts/docx_read.py out.docx --text
python scripts/docx_edit.py replace out.docx --find old --replace new
python scripts/docx_template.py tpl.docx values.json filled.docx
| Task | Command |
|---|---|
| Create from JSON spec | docx_create.py spec.json out.docx |
| Full text (body+tables+headers/footers) | docx_read.py f.docx --text |
| Heading outline + table shapes | docx_read.py f.docx --structure |
| Styles actually used | docx_read.py f.docx --styles |
| Extract embedded images | docx_read.py f.docx --images outdir/ |
| Detect tracked changes/comments | docx_read.py f.docx --revisions |
| Find/replace (formatting kept) | docx_edit.py replace f.docx --find A --replace B -o out.docx |
| Set a table cell | docx_edit.py set-cell f.docx --table 0 --row 1 --col 2 --text X |
| Insert paragraph before index N | docx_edit.py insert f.docx --index N --text X --style Normal |
| Delete paragraph N | docx_edit.py delete f.docx --index N |
| Apply style to paragraph N | docx_edit.py style f.docx --index N --style "Heading 1" |
Fill {{tokens}} | docx_template.py tpl.docx values.json out.docx --strict |
write_file, then run
scripts/docx_create.py. The spec supports: page (size + margins in
mm), header/footer strings, styles (custom paragraph styles with
font, size, bold/italic, hex color), and blocks — heading
(level 1-9), paragraph (either text or a runs list where each run
may set bold/italic/underline), bullet_list, numbered_list,
table (header row rendered bold, rows, optional built-in table
style such as Table Grid), image (path, optional width_mm),
and page_break. The full spec format is documented at the top of
scripts/docx_create.py — read it with read_file when composing.scripts/docx_read.py with exactly one mode flag.
--text returns body paragraphs, all table cell text, and
header/footer text as JSON. --structure returns the heading outline
plus paragraph/table/section counts. --images DIR copies every file
under word/media/ out of the package.scripts/docx_edit.py. replace walks body, tables
(nested included), headers and footers, and preserves run formatting;
add --body-only to skip headers/footers. Pass -o out.docx to keep
the original; omit it to edit in place. Paragraph indices for
insert/delete/style refer to --structure/--text body order.{{name}}-style tokens in the document (letters,
digits, _, ., -; optional inner spaces like {{ name }} are
accepted). Run scripts/docx_template.py with a JSON object of
values. Use --strict to fail when tokens remain unfilled; the JSON
output lists filled counts and unfilled_tokens either way.--text or
--structure and confirm the expected content is present.{{name}} into
several runs. The replace helpers handle this by collapsing the runs;
the replacement inherits the formatting of the run where the match
starts. Mid-token formatting changes are therefore flattened.--revisions only detects insertions,
deletions, format changes, and comments. Text extraction returns the
as-is body (insertions included, deletions omitted, i.e. roughly the
accepted view), but this skill cannot accept/reject revisions or read
comment text. Say so to the user rather than guessing.KeyError. Built-ins like Heading 1, List Bullet,
List Number, Table Grid exist in the default template; custom
styles must be declared in the create spec first.List Number relies on Word's default
numbering; separate lists in one document may continue numbering
instead of restarting. Acceptable for simple docs; warn users needing
precise multi-list numbering.set-cell uses cell.text = ...,
which resets runs in that cell to plain formatting.document.xml corrupts files
easily. Use patch/write_file only for the JSON inputs, never on the
.docx itself.docx_read.py out.docx --text and
check the expected strings appear (and old strings are gone).--strict, or check unfilled_tokens == [].--structure should show the expected heading
outline and table shapes; --styles confirms custom styles applied..docx opens with Document(path) without exception — the
read script exiting 0 is itself a sanity check.