全面的文档创建、编辑和分析功能,支持修订追踪、批注、格式保留和文本提取。当 Claude 需要处理专业文档(.docx 文件)时使用:(1) 创建新文档,(2) 修改或编辑内容,(3) 处理修订追踪,(4) 添加批注,或其他任何文档任务
npx skills add https://github.com/LeastBit/Claude_skills_zh-CN --skill docx
用户可能会要求您创建、编辑或分析 .docx 文件的内容。.docx 文件本质上是一个包含 XML 文件和其他资源的 ZIP 压缩包,您可以读取或编辑这些内容。针对不同任务,您有不同的工具和工作流程可用。
使用下方的"文本提取"或"原始 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 访问。
此工作流程允许您在使用 markdown 规划全面的修订追踪后,在 OOXML 中实现这些修改。关键:要实现完整的修订追踪,您必须系统地实现所有修改。
批处理策略:将相关修改分组为 3-10 个修改一批。这使调试更易管理,同时保持效率。在进入下一批之前测试每一批。
原则:最小化、精确的编辑
实现修订追踪时,只标记实际更改的文本。重复未更改的文本会使编辑更难审阅,看起来也不专业。将替换分解为:[未更改文本] + [删除] + [插入] + [未更改文本]。通过提取原始的 <w:r> 元素并重用它,保留未更改文本的原始 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>'
pandoc --track-changes=all path-to-file.docx -o current.md
定位方法(用于在 XML 中查找修改):
批次组织(每批分组 3-10 个相关修改):
ooxml.md(约 600 行)。读取此文件时切勿设置任何范围限制。 特别注意"Document 库"和"修订追踪模式"章节。python ooxml/scripts/unpack.py <file.docx> <dir>建议的批次分组:
对于每批相关修改:
a. 将文本映射到 XML:在 word/document.xml 中使用 Grep 验证文本如何跨 <w:r> 元素分割。
b. 创建并运行脚本:使用 get_node 查找节点,实现修改,然后 doc.save()。参见 ooxml.md 中的 "Document 库" 章节的模式。
注意:在编写脚本之前,始终立即 grep word/document.xml 以获取当前行号并验证文本内容。每次脚本运行后行号都会改变。
python ooxml/scripts/pack.py unpacked reviewed-document.docx
pandoc --track-changes=all reviewed-document.docx -o verification.md
grep "original phrase" verification.md # 应该找不到
grep "replacement phrase" verification.md # 应该找到
要可视化分析 Word 文档,使用两步过程将其转换为图片:
soffice --headless --convert-to pdf document.docx
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 解析)Comprehensive document creation, editing, and analysis with support for tracked changes, comments, formatting preservation, and text extraction. When Claude needs to work with professional documents (.docx files) for: (1) Creating new documents, (2) Modifying or editing content, (3) Working with tracked changes, (4) Adding comments, or any other document tasks
Comprehensive PDF manipulation toolkit for extracting text and tables, creating new PDFs, merging/splitting documents, and handling forms. When Claude needs to fill in a PDF form or programmatically process, generate, or analyze PDF documents at scale.
Presentation creation, editing, and analysis. When Claude needs to work with presentations (.pptx files) for: (1) Creating new presentations, (2) Modifying or editing content, (3) Working with layouts, (4) Adding comments or speaker notes, or any other presentation tasks
Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.
Use this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.
Use this skill any time a .pptx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates, layouts, speaker notes, or comments. Trigger whenever the user mentions \"deck,\" \"slides,\" \"presentation,\" or references a .pptx filename, regardless of what they plan to do with the content afterward. If a .pptx file needs to be opened, created, or touched, use this skill.
Create and edit Obsidian Flavored Markdown with wikilinks, embeds, callouts, properties, and other Obsidian-specific syntax. Use when working with .md files in Obsidian, or when the user mentions wikilinks, callouts, frontmatter, tags, embeds, or Obsidian notes.
Take leastbit/docx from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.
The instructions reference pip, npm, apt.
Without those the skill loads but fails at the first command.