docx
Installation
SKILL.md
Word documents
Use python-docx for new documents and ordinary edits. For a task-specific generator, run uv run --no-project --with 'python-docx>=1.2' script.py. Bundled scripts declare their own dependencies; run them with uv run --no-project. Resolve paths below relative to this skill, not the user's working directory.
Workflow
- Confirm content, audience, page size, output and template. Inspect the original's paragraphs, runs, tables, headers and sections. Save to a new path; the bundled tools refuse overwriting originals and existing outputs.
- Use built-in headings, named styles, real lists and table column widths. For editing, preserve formatting by changing
run.textor a targeted table cell, not assigning wholeparagraph.textvalues. Read document features for images, fields, TOC, headers/footers and templates. - For comments or redlining, read review edits, then use
scripts/edit.py. Its tracked replacement handles a unique plain-text phrase even across differently formatted runs; it rejects fields, bookmarks and structural revisions it cannot safely handle. - Check content with
Document(output)and runscripts/office.py validate. Render every page and inspect it. Fix truncation, bad pagination, missing images and tables running off the page; re-render changed output into a new directory.
uv run --no-project <skill>/scripts/edit.py replace input.docx tracked.docx "Old wording" "New wording" --author "Reviewer"
uv run --no-project <skill>/scripts/edit.py comment input.docx annotated.docx "Target phrase" "Please verify this" --author "Reviewer"
uv run --no-project <skill>/scripts/edit.py accept tracked.docx accepted.docx
uv run --no-project <skill>/scripts/office.py validate accepted.docx
uv run --no-project <skill>/scripts/office.py render accepted.docx word-preview