Creates, reads, edits, and processes Word .docx and .dotx files. Handles document generation with tables of contents, headers, page numbers, images, tables, revision tracking, and template manipulation.
Ships in document-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
.docx 是由若干 XML 文件打包而成的 ZIP 归档。按任务选择处理方式。
| 任务 | 处理方式 |
|---|---|
| 创建文档 | 用 npm 的 docx 编写脚本,参考下文的注意事项 |
| 编辑现有文档 | 解包、编辑 word/document.xml、用 zip 重新打包。docx-js 无法打开现有文件 |
| 读取内容 | pandoc -t markdown file.docx |
下文的脚本路径均相对于本技能目录。
环境预装了 docx,直接编写脚本并调用 require('docx')。加载失败时才运行 npm install docx。
page: { size: { width: 12240, height: 15840 } }。尺寸单位为 DXA,1 英寸等于 1440 DXA。PageOrientation.LANDSCAPE,docx-js 会在内部互换宽和高。columnWidths 和每个单元格的 width,都用 WidthType.DXA。Google Docs 不能正确处理 PERCENTAGE。各列宽度之和应等于表宽。ShadingType.CLEAR,SOLID 会渲染成黑色。numbering 配置 LevelFormat.BULLET。ImageRun 必须指定 type,例如 "png" 或 "jpg"。PageBreak 放在 Paragraph 内。需要另起一段时创建新的 Paragraph。styles.default 中为每一级实际使用的标题单独配置,例如 heading1: { run: { font: "Arial", size: 32, bold: true }, paragraph: { spacing: { before: 240, after: 120 }, keepNext: true } }。即使已有文档级默认字体,每级也要明确指定字体、段前段后距离(为 0 也要写)和 keepNext。HeadingLevel.*。自定义标题样式需要设置 outlineLevel 才能进入目录。TextRun 中使用 PositionalTab,设置 alignment: PositionalTabAlignment.RIGHT 及 leader: PositionalTabLeader.DOT。生成 .docx 后渲染并逐页查看。
zip -d output.docx '*/' >/dev/null || true # 移除 ZIP 中的目录条目,避免 Word 从云端协作服务打开时拒绝加载
python scripts/office/soffice.py --headless --convert-to pdf output.docx
pdftoppm -jpeg -r 100 output.pdf page
ls page-*.jpg # 查看生成的页面图像
pdftoppm 会按总页数为页码补零,例如 page-01.jpg 至 page-12.jpg。
处理旧版 .doc 前先转换,运行 python scripts/office/soffice.py --headless --convert-to docx file.doc。
python3 -c "import sys,zipfile; zipfile.ZipFile(sys.argv[1]).extractall('unpacked')" doc.docx # 外部 DOCX 视为不受信任的输入。用 zipfile 解包,避免 unzip 恢复符号链接
python scripts/merge_runs.py unpacked/ # 合并碎片化的 run,使文本可搜索
# 直接编辑 unpacked/word/document.xml,保留原排版和缩进
(cd unpacked && rm -f ../out.docx && zip -XrDy ../out.docx .)
python scripts/office/validate.py out.docx --original doc.docx # 执行 XSD 校验。--auto-repair 可修复常见问题
# 若要校验修订,加 --author "<the name you redlined under>",确认每次编辑都有修订标记
Word 会因修订 ID、拼写检查标记等原因,把文字拆成多个 <w:r>(run)。页面上连贯的句子在 XML 中可能被拆开,无法直接查找。merge_runs.py 会合并 word/document.xml 中格式完全相同的相邻 run,保留内容和渲染效果。也可直接输入 .docx,例如 python scripts/merge_runs.py doc.docx -o merged.docx。
修订。 用 --author "<the name you redlined under>" 校验修订(须同时提供 --original)。校验会指出未包在 <w:ins> 或 <w:del> 中的文本修改,这类遗漏在接受修订后的视图中不易察觉。用带有 w:id、w:author 和 w:date 的 <w:ins> 或 <w:del> 包裹调整的 run。<w:del> 中的文本用 <w:delText> 表示。删除段落标记 <w:pPr><w:rPr><w:del w:id=".." w:author=".." w:date=".."/></w:rPr></w:pPr> 表示将该段并入下一段。整段删除时还须用 <w:del> 包裹每个 run。<w:del/> 必须排在 rPr 的其他子元素前面,XML Schema 对此顺序有要求。
运行 python scripts/accept_changes.py in.docx out.docx 可生成接受所有修订的副本。
Word 接受删除段落标记的修订后,会把该段并入下一段,因此 run 全部被删除的段落会消失。其他工具可能只删除文字,留下空段。若原段使用自动编号,就会看到一个空项目符号。
pandoc --track-changes=accept 始终保留独立段落。accept_changes.py(LibreOffice)通常能正确合并,例外是后面紧接一个用于留白的空段。出现空项目符号时,到 XML 中核对段落删除标记,区分查看工具的显示差异与文档本身的结构问题。
批注涉及六个互相关联的文件。若还要改 document.xml,对已解包目录运行辅助脚本,可以省去一次解包和打包。只加批注时可直接处理 .docx。
# 处理已解包的目录,也要放置批注标记时优先采用
python scripts/comment.py unpacked/ "Fees & expenses cap is too low"
python scripts/comment.py unpacked/ "Agreed" --parent 0
# 直接处理 .docx 文件
python scripts/comment.py contract.docx "This cap is too low" -o annotated.docx
脚本会写入 comments.xml、commentsExtended.xml、commentsIds.xml、commentsExtensible.xml,并更新关系和内容类型声明。批注 ID 自动分配。脚本随后打印 <w:commentRangeStart>、<w:commentRangeEnd> 和 <w:commentReference> 片段。将其放入 word/document.xml 的指定位置后,批注才会与文本关联并显示。
npm 包 docx(预装,加载失败才安装)、pandoc、LibreOffice(soffice)、Poppler 的 pdftoppm。
LICENSE.txt (opens in a new tab)scripts/__init__.py (opens in a new tab)scripts/accept_changes.py (opens in a new tab)scripts/comment.py (opens in a new tab)scripts/merge_runs.py (opens in a new tab)scripts/office/helpers/__init__.py (opens in a new tab)scripts/office/helpers/pptx_chart.py (opens in a new tab)scripts/office/helpers/pptx_slide.py (opens in a new tab)scripts/office/helpers/pptx_theme.py (opens in a new tab)scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd (opens in a new tab)scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd (opens in a new tab)scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd (opens in a new tab)scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd (opens in a new tab)scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd (opens in a new tab)scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd (opens in a new tab)scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd (opens in a new tab)scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd (opens in a new tab)scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd (opens in a new tab)scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd (opens in a new tab)scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
4 skills in this plugin
/pdf用户提及 .pdf 文件或需要生成、处理 PDF 时使用。适用于阅读和提取文本或表格、合并和拆分文件、旋转页面、添加水印、创建 PDF、填写表单、加密或解密、导出图片,以及用 OCR 将扫描件转换为可搜索的文档。/pptx凡涉及 .pptx 或 .potx 文件均使用本技能,无论文件用作输入还是输出。适用于制作幻灯片、路演稿和演示文稿,读取或提取内容,编辑、合并、拆分文件,以及使用模板、版式、演讲者备注和批注。即使提取的内容随后用于邮件或摘要,仍应使用本技能。用户提及 deck、slides、presentation、幻灯片、演示文稿或相应文件名时启用。/xlsx当电子表格是主要输入或交付物时使用。适用于打开、读取、编辑或修复 .xlsx、.xlsm、.xltx、.csv 或 .tsv 文件,例如增列、写公式、调整格式、制作图表或清洗杂乱数据,也适用于新建表格及转换表格文件格式。用户提到文件名或路径并要求处理或生成该文件时应启用。整理错行、错位表头和无效数据并交付规整表格也适用。主要交付物须为电子表格文件。Word 文档、HTML 报告、独立 Python 脚本、数据库流程或 Google Sheets API 集成使用各自的工作流。/document-skills:docxfrom document-skills
npx claudepluginhub leastbit/claude_skills_zh-cn --plugin document-skillsOther plugins' skills for the same job