docx

Create, read, edit, and template Word .docx files using python-docx CLI scripts.

Updated Jul 3, 2026
One-click install
npx skills add https://github.com/CHENHUI-X/toolbox --skill docx-chenhui-x
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: docx
Source: https://github.com/CHENHUI-X/toolbox/tree/main/official-skills/productivity/docx
Command: npx skills add https://github.com/CHENHUI-X/toolbox --skill docx-chenhui-x

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires python-docx, lxml, and includes scripts (resource) and references (resource) components.

What problem does it solve? Working with Microsoft Word documents programmatically is error-prone: text gets fragmented across runs, tracked changes and comments live in raw XML, and templates with placeholders break easily. This Skill provides tested CLI scripts that handle creation, reading, editing, templating, revision resolution, comment management, and package health checks for .docx files. ## Core Features & Use Cases - Document Creation & Templating: Build .docx files from a JSON spec (headings, tables, images, styles, TOC, page numbers) or fill {{token}} placeholders in existing templates from JSON data. - Editing & Review: Find-and-replace with formatting preserved, insert/delete/style paragraphs, set table cells, list and accept/reject tracked changes, and add or delete anchored comments. - Inspection & Validation: Extract full text, heading outlines, styles, and embedded images; detect revisions; and health-check the package for corrupt parts, dangling relationships, or missing styles. - Use Case: You receive a contract template with {{client_name}} and {{date}} placeholders plus reviewer tracked changes. Fill the tokens with docx_template.py, accept all revisions with docx_revisions.py, then verify the result with docx_validate.py. ## Quick Start Ask the AI to create a Word report from a JSON spec or to fill placeholders in your .docx template using the docx skill's scripts.

Frequently Asked Questions about docx

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fill placeholders in a Word template with Python?

Put {{token}} placeholders in the .docx and run docx_template.py with a JSON file of values. It replaces tokens across body, tables, headers, and footers while preserving run formatting, and --strict fails if any token remains unfilled.

How to accept or reject tracked changes in a .docx programmatically?

Use docx_revisions.py to list every w:ins and w:del with id, author, and text, then run accept-all, reject-all, or accept/reject a single revision by --id. It covers run-level changes in body, tables, headers, and footers.

Does python-docx support adding comments to Word documents?

Yes. The native add_comment API exists in python-docx 1.2 and later; for older versions the script falls back to building word/comments.xml and range markers directly at the XML level. Listing and deleting comments always work at the XML level.

Can python-docx convert a Word document to PDF?

No, python-docx cannot render PDFs. Convert headlessly with LibreOffice using soffice --headless --convert-to pdf, which requires LibreOffice installed on the system for layout-faithful output.

Why does find-and-replace miss text in my Word document?

Word often fragments text into multiple runs, so a phrase may span several runs. Run docx_edit.py normalize first to merge adjacent runs with identical formatting, after which replace matches reliably.

What file formats does this docx tooling not support?

It does not support legacy .doc files, .odt, or WYSIWYG layout work. It also cannot resolve paragraph-mark revisions, table-row revisions, format-change records, or moves—those must be handled in Word itself.