name: docx description: 全面的文档创建、编辑和分析,支持修订追踪、评论、格式保持和文本提取。当Claude需要处理专业文档(.docx文件)以创建新文档、修改内容、处理修订追踪或添加评论时。 source: anthropics/skills license: Apache-2.0
DOCX 处理
工作流决策树
- 读取/分析:使用文本提取或原始XML访问
- 创建新文档:使用docx-js(JavaScript)
- 编辑现有文档:使用OOXML编辑或修订追踪工作流
读取内容
使用Pandoc进行文本提取
# 转换为带修订追踪的Markdown
pandoc --track-changes=all file.docx -o output.md
原始XML访问
# 解压文档
unzip document.docx -d unpacked/
# 关键文件:
# word/document.xml - 主要内容
# word/comments.xml - 评论
# word/media/ - 图像
创建新文档(docx-js)
import { Document, Paragraph, TextRun, Packer } from 'docx';
import fs from 'fs';
const doc = new Document({
sections: [{
children: [
new Paragraph({
children: [
new TextRun({ text: "Hello ", bold: true }),
new TextRun({ text: "World", italics: true })
]
})
]
}]
});
const buffer = await Packer.toBuffer(doc);
fs.writeFileSync('document.docx', buffer);
编辑现有文档
简单编辑
- 解压:
unzip doc.docx -d unpacked/ - 编辑
word/document.xml - 重新打包:
cd unpacked && zip -r ../edited.docx .
修订追踪(红字修改)
对于专业文档,使用修订追踪:
<!-- 删除 -->
<w:del w:author="作者" w:date="2025-01-01T00:00:00Z">
<w:r><w:delText>旧文本</w:delText></w:r>
</w:del>
<!-- 插入 -->
<w:ins w:author="作者" w:date="2025-01-01T00:00:00Z">
<w:r><w:t>新文本</w:t></w:r>
</w:ins>
转换为图像
# DOCX 到 PDF
soffice --headless --convert-to pdf document.docx
# PDF 到图像
pdftoppm -jpeg -r 150 document.pdf page
最佳实践
- 使用 Pandoc 进行文本提取
- 使用 docx-js 创建新文档
- 对于法律/商业文档,始终使用修订追踪
- 编辑时保留原始 RSIDs