docx
它能做什么
这项技能处理 Microsoft Word 文件,从读取结构到编辑,再到创建新文件。它适合需要修改或制作 Word 文档、并保留其样式的人。
适用场景
- ✓当你有一个 Word 文件,需要提取其文本或结构时。
- ✓当你需要编辑 Word 文档并保留其样式和版式的时候。
- ✓当你希望根据简要说明创建一份新的 Word 文档时。
技能链接
https://github.com/TokenRhythm/opensquilla/blob/main/src/opensquilla/skills/bundled/docx/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我更新这份 Word 合同中的价格,并保持原有格式不变。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会先查看文件的结构,了解其中的内容,然后直接在原文件中编辑,使样式和版式保持不变。如果是新文档,则根据你的说明从头构建文件。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
docx
Work with Microsoft Word .docx files. The format is OOXML — a zip container
holding XML parts (word/document.xml, styles.xml, numbering.xml, headers,
footers, relationships). Treat structure as primary; rendered text is a view.
Decide the path first
Pick one path up front. The right path depends only on what is on disk before you start.
| You have | Goal | Path |
|---|---|---|
Existing .docx |
Read text/structure | A. Inspect |
Existing .docx |
Modify content while keeping styles | B. Edit-in-place |
| Nothing or a brief | Build a new doc | C. Create from scratch |
If the user hands you a doc and asks for changes, default to path B and treat the input as the visual style baseline. Only choose path C when the user says "start fresh" or there is no input.
Path A: Inspect
Dump structure as JSON for inspection without mutating anything.
python {baseDir}/scripts/inspect_docx.py /path/to/doc.docx
Output schema:
{
"paragraphs": [{"index": 0, "text": "...", "style": "Heading 1"}, ...],
"tables": [[["row0,col0", "row0,col1"], ...], ...],
"sections": 1,
"has_tracked_changes": false
}
Use this whenever you need to see what is in the doc before deciding how to edit. The output is stable and machine-readable — diff two inspect outputs to verify a round-trip preserved everything you intended.
Path B: Edit in place
Two sub-strategies; pick by how invasive the edit is.
B1. Run-level text replacement (preferred)
When the change is "swap this string" or "fill these placeholders": mutate runs in place. This preserves all theme/style/font settings.
python {baseDir}/scripts/edit_docx.py input.docx ops.json --out output.docx
ops.json is a list of operations:
[
{"op": "replace_run", "para": 0, "run": 0, "text": "Q3 Review"},
{"op": "replace_text", "find": "{{CLIENT}}", "with": "Acme Corp"}
]
Edit at the run level, not the paragraph level — replacing whole paragraph text drops formatting. If a placeholder spans multiple runs (often happens when the original template applied bold/italic mid-word), the helper script collapses runs into the first one and clears the rest.
B2. Structural edits (sections / page layout / numbering)
python-docx exposes paragraphs, tables, and runs but has limited support for
page layout, numbering definitions, and tracked changes. For those, unzip the
.docx, patch word/document.xml and adjacent parts, and repack:
mkdir _unpacked && (cd _unpacked && unzip -q ../input.docx)
# edit _unpacked/word/document.xml
(cd _unpacked && zip -q -r ../output.docx . -x "*.DS_Store")
Rules when patching XML:
- Use
defusedxml.ElementTreeorlxml, not stdlibxml.etree.ElementTree. ET drops or rewrites namespace prefixes (w:,r:) in ways Word refuses to load. - Preserve
xml:space="preserve"on<w:t>elements that hold leading or trailing whitespace. [Content_Types].xmlmust list every part type. Removing a header without also removing its override entry yields a "repair" prompt in Word.- Numbering definitions live in
numbering.xml; bullet/number changes must patch the numbering ID, not just the visible text.
When done, validate by opening in LibreOffice headless before declaring success — silent failures are common.
Path C: Create from scratch
For a simple Markdown source, run the export script with the Markdown on stdin:
python {baseDir}/scripts/export_markdown_docx.py --out out.docx < draft.md
For structured content, use a JSON specification:
python {baseDir}/scripts/create_docx.py spec.json --out out.docx
spec.json describes content declaratively:
{
"metadata": {"title": "Q3 Review", "author": "Wei E."},
"body": [
{"kind": "heading", "level": 1, "text": "Q3 Review"},
{"kind": "paragraph", "text": "Revenue +18% YoY."},
{"kind": "table", "rows": [["Metric", "Value"], ["Revenue", "$2.1M"]]}
]
}
For programmatic use call python-docx directly:
from docx import Document
doc = Document()
doc.add_heading("Q3 Review", level=1)
doc.add_paragraph("Revenue +18% YoY.")
table = doc.add_table(rows=2, cols=2)
table.rows[0].cells[0].text = "Metric"
doc.save("out.docx")
See references/python_docx.md for paragraphs, styles, numbering, tables, headers/footers, and section breaks.
Tracked changes
Tracked changes are stored in `word/document
常见问题
它会保留我的格式吗?
会。编辑时,该技能将现有文件作为样式基准并予以保留。
它能处理修订记录吗?
可以。该技能涵盖查看 Word 文件中的修订记录。
如果我想要一个全新的文件呢?
如果你说明要从头开始,或没有输入文件,该技能就会构建一份新文档。
详情
作者的原始描述
Read, inspect, edit, or create Microsoft Word `.docx` documents, including structured text extraction, style-preserving edits, tracked-change review, and generation from a brief.
repo: TokenRhythm/opensquilla
热度
- GitHub 星标
- 7.1k
- 排名
- #13588
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
browser-use
7.1k让你的智能体在 OpenSquilla Desktop 侧边栏浏览器中打开、阅读和操作网页,包括填写表单和进行视觉检查。
deep-research
7.1k教你的智能体进行多轮研究,使用已保存的计划、已追踪的来源,并生成带引用的长篇报告。
html-coder
7.1k帮你的智能体编写结构清晰的 HTML 页面,包含无障碍表单、媒体和 HTML5 功能,并可作为网页预览打开。
pdf-toolkit
7.1k帮你的智能体从 PDF 中提取文本和表格,合并或拆分文件,填写表单字段,并根据数据创建新的 PDF。