The Agent Skills Directory
npx skills add https://smithery.ai/skills/davila7/docx.docx 文件是一个包含 XML 文件和资源的 ZIP 归档文件。使用文本提取、原始 XML 访问或修订工作流来创建、编辑或分析 Word 文档。应用此技能进行专业文档处理、跟踪更改和内容操作。
使用此技能创建文档时,请始终考虑添加科学图表和示意图以增强视觉传达。
如果您的文档尚未包含示意图或图表:
对于新文档: 默认应生成科学示意图,以直观地表示文本中描述的关键概念、工作流、架构或关系。
如何生成示意图:
python scripts/generate_schematic.py "your diagram description" -o figures/output.png
AI 将自动:
何时添加示意图:
有关创建示意图的详细指导,请参阅 scientific-schematics 技能文档。
使用下面的“文本提取”或“原始 XML 访问”部分
使用“创建新的 Word 文档”工作流
您自己的文档 + 简单更改 使用“基本 OOXML 编辑”工作流
他人的文档 使用 “修订工作流” (推荐默认)
法律、学术、商业或政府文档 使用 “修订工作流” (必需)
要读取文档的文本内容,请使用 pandoc 将文档转换为 markdown。Pandoc 在保留文档结构和显示跟踪更改方面提供了出色的支持:
# 将文档转换为 markdown 并保留跟踪更改
pandoc --track-changes=all path-to-file.docx -o output.md
# 选项:--track-changes=accept/reject/all
原始 XML 访问是以下功能所必需的:批注、复杂格式、文档结构、嵌入媒体和元数据。对于任何这些功能,请解包文档并读取其原始 XML 内容。
python ooxml/scripts/unpack.py <office_file> <output_directory>
word/document.xml - 主要文档内容word/comments.xml - 在 document.xml 中引用的批注word/media/ - 嵌入的图像和媒体文件<w:ins>(插入)和 <w:del>(删除)标签从头开始创建新的 Word 文档时,请使用 docx-js ,它允许您使用 JavaScript/TypeScript 创建 Word 文档。
docx-js.md(约 500 行)。阅读此文件时切勿设置任何范围限制。 在继续创建文档之前,请阅读完整的文件内容以了解详细的语法、关键的格式规则和最佳实践。编辑现有的 Word 文档时,请使用 Document 库(一个用于 OOXML 操作的 Python 库)。该库自动处理基础设施设置,并提供文档操作方法。对于复杂场景,您可以通过该库直接访问底层 DOM。
ooxml.md(约 600 行)。阅读此文件时切勿设置任何范围限制。 阅读完整的文件内容以了解 Document 库 API 和用于直接编辑文档文件的 XML 模式。python ooxml/scripts/unpack.py <office_file> <output_directory>python ooxml/scripts/pack.py <input_directory> <office_file>Document 库为常见操作提供了高级方法,也为复杂场景提供了直接的 DOM 访问。
此工作流允许在 OOXML 中实施之前,使用 markdown 规划全面的跟踪更改。关键:要完成跟踪更改,请系统地实施所有更改。
批处理策略:将相关的更改分组为每批 3-10 个更改。这使得调试易于管理,同时保持效率。在进入下一批之前测试每一批。
原则:最小化、精确的编辑 实施跟踪更改时,只标记实际更改的文本。重复未更改的文本会使编辑更难审查,并且显得不专业。将替换分解为:[未更改文本] + [删除] + [插入] + [未更改文本]。通过从原始文本中提取 <w:r> 元素并重用它,来保留原始运行(run)的 RSID 用于未更改的文本。
示例 - 将句子中的“30 days”改为“60 days”:
# 错误 - 替换整个句子
'<w:del><w:r><w:delText>The term is 30 days.</w:delText></w:r></w:del><w:ins><w:r><w:t>The term is 60 days.</w:t></w:r></w:ins>'
# 正确 - 只标记更改的内容,为未更改的文本保留原始的 <w:r>
'<w:r w:rsidR="00AB12CD"><w:t>The term is </w:t></w:r><w:del><w:r><w:delText>30</w:delText></w:r></w:del><w:ins><w:r><w:t>60</w:t></w:r></w:ins><w:r w:rsidR="00AB12CD"><w:t> days.</w:t></w:r>'
获取 markdown 表示:将文档转换为 markdown 并保留跟踪更改:
pandoc --track-changes=all path-to-file.docx -o current.md
识别并分组更改:审查文档并识别所有需要的更改,将它们组织成逻辑批次:
定位方法(用于在 XML 中查找更改):
* 章节/标题编号(例如,“Section 3.2”、“Article IV”)
* 段落标识符(如果有编号)
* 带有独特周围文本的 Grep 模式
* 文档结构(例如,“first paragraph”、“signature block”)
* **不要使用 markdown 行号** - 它们不映射到 XML 结构
批次组织(每批分组 3-10 个相关更改):
* 按章节:“Batch 1: Section 2 amendments”、“Batch 2: Section 5 updates”
* 按类型:“Batch 1: Date corrections”、“Batch 2: Party name changes”
* 按复杂度:从简单的文本替换开始,然后处理复杂的结构更改
* 按顺序:“Batch 1: Pages 1-3”、“Batch 2: Pages 4-6”
3. 阅读文档并解包:
* **强制要求 - 完整阅读文件** :从头到尾完整阅读 [`ooxml.md`](https://smithery.ai/skills/davila7/docx/.well-known/skills/docx/ooxml.md)(约 600 行)。**阅读此文件时切勿设置任何范围限制。** 特别注意“Document Library”和“Tracked Change Patterns”部分。
* **解包文档**:`python ooxml/scripts/unpack.py <file.docx> <dir>`
* **记下建议的 RSID**:解包脚本会建议一个用于跟踪更改的 RSID。复制此 RSID 用于步骤 4b。
4. 分批实施更改:将更改按逻辑分组(按章节、按类型或按邻近性),并在单个脚本中一起实施。这种方法:
* 使调试更容易(批次越小,越容易隔离错误)
* 允许增量进展
* 保持效率(每批 3-10 个更改效果很好)
建议的批次分组:
* 按文档章节(例如,“Section 3 changes”、“Definitions”、“Termination clause”)
* 按更改类型(例如,“Date changes”、“Party name updates”、“Legal term replacements”)
* 按邻近性(例如,“Changes on pages 1-3”、“Changes in first half of document”)
对于每一批相关更改:
a. 将文本映射到 XML:在 word/document.xml 中 grep 文本,以验证文本是如何跨 <w:r> 元素分割的。
b. 创建并运行脚本:使用 get_node 查找节点,实施更改,然后 doc.save()。有关模式,请参见 ooxml.md 中的 “Document Library” 部分。
注意:在编写脚本之前,请始终立即 grep word/document.xml 以获取当前行号并验证文本内容。每次脚本运行后,行号都会改变。
打包文档:所有批次完成后,将解包的目录转换回 .docx:
python ooxml/scripts/pack.py unpacked reviewed-document.docx
最终验证:对完整文档进行全面检查:
将最终文档转换为 markdown:
pandoc --track-changes=all reviewed-document.docx -o verification.md
验证所有更改是否正确应用:
grep "original phrase" verification.md # 应该找不到
grep "replacement phrase" verification.md # 应该找到
检查是否引入了意外的更改
为了可视化分析 Word 文档,请使用两步过程将其转换为图像:
将 DOCX 转换为 PDF:
soffice --headless --convert-to pdf document.docx
将 PDF 页面转换为 JPEG 图像:
pdftoppm -jpeg -r 150 document.pdf page
这将创建类似 page-1.jpg、page-2.jpg 等文件。
选项:
-r 150:设置分辨率为 150 DPI(根据需要调整质量/大小平衡)-jpeg:输出 JPEG 格式(如果偏好 PNG,请使用 -png)-f N:要转换的起始页(例如,-f 2 从第 2 页开始)-l N:要转换的结束页(例如,-l 5 在第 5 页停止)page:输出文件的前缀特定范围的示例:
pdftoppm -jpeg -r 150 -f 2 -l 5 document.pdf page # 仅转换第 2-5 页
重要:为 DOCX 操作生成代码时:
必需的依赖项(如果不可用,请安装):
sudo apt-get install pandoc(用于文本提取)npm install -g docx(用于创建新文档)sudo apt-get install libreoffice(用于 PDF 转换)sudo apt-get install poppler-utils(用于 pdftoppm 将 PDF 转换为图像)pip install defusedxml(用于安全的 XML 解析)每周安装次数
194
来源
首次出现
2026年3月6日
安全审计
安装于
claude-code110
codex53
opencode52
cursor51
github-copilot42
cline40
A .docx file is a ZIP archive containing XML files and resources. Create, edit, or analyze Word documents using text extraction, raw XML access, or redlining workflows. Apply this skill for professional document processing, tracked changes, and content manipulation.
When creating documents with this skill, always consider adding scientific diagrams and schematics to enhance visual communication.
If your document does not already contain schematics or diagrams:
For new documents: Scientific schematics should be generated by default to visually represent key concepts, workflows, architectures, or relationships described in the text.
How to generate schematics:
python scripts/generate_schematic.py "your diagram description" -o figures/output.png
The AI will automatically:
When to add schematics:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
For detailed guidance on creating schematics, refer to the scientific-schematics skill documentation.
Use "Text extraction" or "Raw XML access" sections below
Use "Creating a new Word document" workflow
Your own document + simple changes Use "Basic OOXML editing" workflow
Someone else's document Use "Redlining workflow" (recommended default)
Legal, academic, business, or government docs Use "Redlining workflow" (required)
To read the text contents of a document, convert the document to markdown using pandoc. Pandoc provides excellent support for preserving document structure and can show tracked changes:
# Convert document to markdown with tracked changes
pandoc --track-changes=all path-to-file.docx -o output.md
# Options: --track-changes=accept/reject/all
Raw XML access is required for: comments, complex formatting, document structure, embedded media, and metadata. For any of these features, unpack a document and read its raw XML contents.
python ooxml/scripts/unpack.py <office_file> <output_directory>
word/document.xml - Main document contentsword/comments.xml - Comments referenced in document.xmlword/media/ - Embedded images and media files<w:ins> (insertions) and <w:del> (deletions) tagsWhen creating a new Word document from scratch, use docx-js , which allows you to create Word documents using JavaScript/TypeScript.
docx-js.md (~500 lines) completely from start to finish. NEVER set any range limits when reading this file. Read the full file content for detailed syntax, critical formatting rules, and best practices before proceeding with document creation.When editing an existing Word document, use the Document library (a Python library for OOXML manipulation). The library automatically handles infrastructure setup and provides methods for document manipulation. For complex scenarios, you can access the underlying DOM directly through the library.
ooxml.md (~600 lines) completely from start to finish. NEVER set any range limits when reading this file. Read the full file content for the Document library API and XML patterns for directly editing document files.python ooxml/scripts/unpack.py <office_file> <output_directory>python ooxml/scripts/pack.py <input_directory> <office_file>The Document library provides both high-level methods for common operations and direct DOM access for complex scenarios.
This workflow allows planning comprehensive tracked changes using markdown before implementing them in OOXML. CRITICAL : For complete tracked changes, implement ALL changes systematically.
Batching Strategy : Group related changes into batches of 3-10 changes. This makes debugging manageable while maintaining efficiency. Test each batch before moving to the next.
Principle: Minimal, Precise Edits When implementing tracked changes, only mark text that actually changes. Repeating unchanged text makes edits harder to review and appears unprofessional. Break replacements into: [unchanged text] + [deletion] + [insertion] + [unchanged text]. Preserve the original run's RSID for unchanged text by extracting the <w:r> element from the original and reusing it.
Example - Changing "30 days" to "60 days" in a sentence:
# BAD - Replaces entire sentence
'<w:del><w:r><w:delText>The term is 30 days.</w:delText></w:r></w:del><w:ins><w:r><w:t>The term is 60 days.</w:t></w:r></w:ins>'
# GOOD - Only marks what changed, preserves original <w:r> for unchanged text
'<w:r w:rsidR="00AB12CD"><w:t>The term is </w:t></w:r><w:del><w:r><w:delText>30</w:delText></w:r></w:del><w:ins><w:r><w:t>60</w:t></w:r></w:ins><w:r w:rsidR="00AB12CD"><w:t> days.</w:t></w:r>'
Get markdown representation : Convert document to markdown with tracked changes preserved:
pandoc --track-changes=all path-to-file.docx -o current.md
Identify and group changes : Review the document and identify ALL changes needed, organizing them into logical batches:
Location methods (for finding changes in XML):
* Section/heading numbers (e.g., "Section 3.2", "Article IV")
* Paragraph identifiers if numbered
* Grep patterns with unique surrounding text
* Document structure (e.g., "first paragraph", "signature block")
* **DO NOT use markdown line numbers** \- they don't map to XML structure
Batch organization (group 3-10 related changes per batch):
* By section: "Batch 1: Section 2 amendments", "Batch 2: Section 5 updates"
* By type: "Batch 1: Date corrections", "Batch 2: Party name changes"
* By complexity: Start with simple text replacements, then tackle complex structural changes
* Sequential: "Batch 1: Pages 1-3", "Batch 2: Pages 4-6"
3. Read documentation and unpack :
* **MANDATORY - READ ENTIRE FILE** : Read [`ooxml.md`](https://smithery.ai/skills/davila7/docx/.well-known/skills/docx/ooxml.md) (~600 lines) completely from start to finish. **NEVER set any range limits when reading this file.** Pay special attention to the "Document Library" and "Tracked Change Patterns" sections.
* **Unpack the document** : `python ooxml/scripts/unpack.py <file.docx> <dir>`
* **Note the suggested RSID** : The unpack script will suggest an RSID to use for your tracked changes. Copy this RSID for use in step 4b.
4. Implement changes in batches : Group changes logically (by section, by type, or by proximity) and implement them together in a single script. This approach:
* Makes debugging easier (smaller batch = easier to isolate errors)
* Allows incremental progress
* Maintains efficiency (batch size of 3-10 changes works well)
Suggested batch groupings:
* By document section (e.g., "Section 3 changes", "Definitions", "Termination clause")
* By change type (e.g., "Date changes", "Party name updates", "Legal term replacements")
* By proximity (e.g., "Changes on pages 1-3", "Changes in first half of document")
For each batch of related changes:
a. Map text to XML : Grep for text in word/document.xml to verify how text is split across <w:r> elements.
b. Create and run script : Use get_node to find nodes, implement changes, then doc.save(). See "Document Library" section in ooxml.md for patterns.
Note : Always grep word/document.xml immediately before writing a script to get current line numbers and verify text content. Line numbers change after each script run.
Pack the document : After all batches are complete, convert the unpacked directory back to .docx:
python ooxml/scripts/pack.py unpacked reviewed-document.docx
Final verification : Do a comprehensive check of the complete document:
Convert final document to markdown:
pandoc --track-changes=all reviewed-document.docx -o verification.md
Verify ALL changes were applied correctly:
grep "original phrase" verification.md # Should NOT find it
grep "replacement phrase" verification.md # Should find it
Check that no unintended changes were introduced
To visually analyze Word documents, convert them to images using a two-step process:
Convert DOCX to PDF :
soffice --headless --convert-to pdf document.docx
Convert PDF pages to JPEG images :
pdftoppm -jpeg -r 150 document.pdf page
This creates files like page-1.jpg, page-2.jpg, etc.
Options:
-r 150: Sets resolution to 150 DPI (adjust for quality/size balance)-jpeg: Output JPEG format (use -png for PNG if preferred)-f N: First page to convert (e.g., -f 2 starts from page 2)-l N: Last page to convert (e.g., -l 5 stops at page 5)page: Prefix for output filesExample for specific range:
pdftoppm -jpeg -r 150 -f 2 -l 5 document.pdf page # Converts only pages 2-5
IMPORTANT : When generating code for DOCX operations:
Required dependencies (install if not available):
sudo apt-get install pandoc (for text extraction)npm install -g docx (for creating new documents)sudo apt-get install libreoffice (for PDF conversion)sudo apt-get install poppler-utils (for pdftoppm to convert PDF to images)pip install defusedxml (for secure XML parsing)Weekly Installs
194
Source
First Seen
Mar 6, 2026
Security Audits
Installed on
claude-code110
codex53
opencode52
cursor51
github-copilot42
cline40
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
31,600 周安装