Preface¶
Modifying Word documents within an Agent typically involves regenerating the entire file using a library or simply modifying plain text. However, styles, headers/footers, sections, numbering, revision history (track changes), and images on complex templates are easily lost or misaligned. Furthermore, handling layouts for Chinese official documents (GB/T 9704) relies solely on “Save As” or simple text replacement, which is often insufficient for stability.
Below is an introduction to the docx optimized version (coordinate @user_c66b8218/docx007-skill) on SkillHub. It treats .docx files as Open XML within a ZIP package, following a workflow of Unpack → Modify XML in-place → Repack, supported by validation and rendering tools. Its goal is to preserve the original formatting as much as possible during creation, editing, form filling, reformatting, and format conversion.
What is this¶
docx optimized version is a community-published (community) Agent Skill categorized under office-efficiency. It is maintained by SkillHub user user_c66b8218, with the current store version at 1.0.0. The Skill package includes a runnable Python toolchain (lxml, python-docx) and relies on local LibreOffice and poppler-utils. It does not require an API Key (requires_api_key=false).
In one sentence: It processes Microsoft Word .docx files within an Agent session using a READ → ACT → VERIFY workflow—reading structure, modifying XML within an unpacked directory or creating new documents, and then validating and rendering to PDF/PNG for visual inspection. It provides specific instructions and script support for Chinese/CJK and GB/T 9704 official document layouts.
Core Features¶
The following capabilities are derived from the SKILL.md and references/ documentation within the Skill package and can be selected based on task routing:
- Creation (Pipeline A): When no existing
.docxis available, usepython-docxto create a new document (seereferences/create.md). - Filling & Editing (Pipeline B): Perform run-aware find-and-replace, placeholder filling, and insertion of paragraphs/headings on existing
.docxfiles after unpacking (seereferences/edit.md). - Applying Styles & Templates (Pipeline C): Reformat or apply templates, including two strategies: Overlay and Base-Replace (see
references/format.md). - Reading & Analysis:
docx_reader.pyprovides structure overviews,--outlinefor heading trees,--preview, and--diff-againstcomparisons. - Format Preservation: Unpacking, editing, and repacking aims to preserve styles, themes, headers/footers, multi-section layouts, numbering, revisions (track changes), fields, and embedded images. The Skill explicitly emphasizes prioritizing editing over full-package regeneration.
- Validation & Visualization:
docx_validate.pyacts as a gatekeeper for element order and other constraints;docx_render.pyoutputs PDFs and paginated PNGs via LibreOffice for easy verification of layouts and CJK fonts. - Format Conversion:
libreoffice_convert.pysupports converting.doc/.odt/.rtfto.docxor PDF. - Chinese & Official Documents: Support for UTF-8,
w:rFontsEast Asian fonts, and font size tables; for official documents, it references GB/T 9704 (e.g., FangSong_GB2312 size 3 for body text, SimHei for titles, etc., seereferences/cjk-guide.md).
The store-side SkillHub rating is 100000, with 1342 downloads (statistics based on SkillHub page scraping).
Installation & Activation¶
Environment Dependencies¶
Before running scripts in the Skill directory, the dependencies declared in the package must be met:
- Python:
python-docx,lxml,Pillow - System:
libreoffice(soffice),poppler-utils(pdftoppm) - Fonts: It is recommended to install Noto Sans CJK / Noto Serif CJK for better CJK rendering.
After installation, you can run an environment self-check in the Skill root directory:
python3 scripts/docx_doctor.py
The output should be READY.
Installing via SkillHub CLI¶
If the CLI is not installed, follow the official SkillHub instructions to install it:
curl -fsSL https://skillhub-1388575217.cos.ap-guangzhou.myqcloud.com/install/install.sh | bash
Install the Skill to the current Agent’s skills directory (must use --dir, otherwise the default ./skills/ might not be loaded by the Agent). For example, in Cursor:
skillhub install docx007-skill --namespace user_c66b8218 --dir ~/.cursor/skills/
Common paths for other clients (from SkillHub installation docs): Claude Code uses ~/.claude/skills/; Codex uses ~/.codex/skills/ or .agents/skills/ in the project. Typically, a restart or reload of the Agent is required to recognize the new Skill.
Installing via Natural Language¶
The prompt provided on the SkillHub page is: According to https://skillhub.cn/install/skillhub.md, install @user_c66b8218/docx007-skill.
Typical Usage¶
The typical flow aligns with references/quickstart.md inside the Skill: First READ, then ACT, and finally VERIFY. The following commands are executed in the Skill package root directory (the path containing scripts/).
1. Read original structure
python3 scripts/docx_reader.py input.docx --outline
2. Unpack, Replace, Repack
python3 scripts/docx_unpack.py input.docx /tmp/wd
python3 scripts/docx_replace_text.py /tmp/wd --find OLD --replace NEW
python3 scripts/docx_pack.py /tmp/wd output.docx
3. Validate, Compare, Render for visual check
python3 scripts/docx_validate.py output.docx --report
python3 scripts/docx_reader.py output.docx --diff-against input.docx
python3 scripts/docx_render.py output.docx --out /tmp/rev
Template placeholder filling example (in the same unpacked directory):
python3 scripts/docx_fill_placeholders.py /tmp/wd --data '{"name":"Zhang San"}'
Legacy .doc files can be converted first:
python3 scripts/libreoffice_convert.py old.doc --to docx --outdir .
In Agent conversations, trigger words include Word, docx, document, official document, template application, report, mail merge, etc. (see Skill metadata triggers). The Agent should follow Skill requirements: any deliverable must pass docx_validate.py and --diff-against, and complete the PNG visual inspection via docx_render.py.
Applicable Scenarios & Notes¶
Who is it for
- Scenarios where you need to modify contracts, reports, papers, or official documents within an Agent while preserving the original template layout.
- When performing batch placeholder filling, run-aware replacement, or inserting headings with outline levels, and you are concerned about losing formatting when
python-docxrewrites the entire document alone. - Developers handling Chinese/CJK or GB/T 9704 official document layouts who are willing to edit XML according to rules such as Open XML element order.
Limitations & Notes
- Depends on local LibreOffice and poppler; the rendering pipeline may require additional configuration in headless environments (see
references/troubleshooting.mdfor troubleshooting). - Open XML has strict constraints on element order, revision marks (
w:ins/w:del), and units (half-points, dxa, EMU). Violations will causedocx_validate.pyto fail; modifications must be made in accordance with documents likereferences/openxml-element-order.md. - The SkillHub store version is 1.0.0; the
SKILL.mdfrontmatter in the package contains an internal version field, which should be based on the actual installed package. - This Skill is a tool and workflow guide; it does not replace compliance approval for confidential documents. Please operate sensitive files in an isolated environment.
Conclusion¶
docx optimized version treats Word as an auditable XML package and uses a script chain to fix the steps of Read → Modify → Verify → View. It is suitable for reproducible, low-format-loss .docx processing within an Agent. Official entry and installation coordinates:
- SkillHub Page: https://www.skillhub.cn/skills/user_c66b8218/docx007-skill
- API Coordinates: https://api.skillhub.cn/user_c66b8218/docx007-skill
- Installation:
skillhub install docx007-skill --namespace user_c66b8218 --dir <your Agent skills directory>