Community编程与开发github.com

docx

在用户需要创建、读取、编辑或操作 Word 文档(.docx 文件)或 Word 模板(.dotx 文件)时使用。触发条件包括:任何提及 'Word 文档'、'word document'、'.docx'、'.dotx' 的表述,或要求生成带有目录、标题、页码、信头等格式的专业文档。也适用于从 .docx 或 .dotx 文件中提取或重新组织内容、在文档中插入或替换图片、在 Word 文件中执行查找替换、处理修订或批注,或将内容转换为精美的 Word 文档。如果用户要求以 Word 或 .docx 文件形式交付 '报告'、'备忘录'、'信函'、'模板' 等,请使用此技能。不要用于 PDF、电子表格、Google Docs 或与文档生成无关的通用编码任务。

docx 是什么?

此技能专为在 AI 代理(如 Claude Code、Cursor、Codex)中操作 Word 文档(.docx 和 .dotx)而设计。它提供三种不同的方法来处理文档:通过编写 docx(npm)脚本创建新文档、使用 zip/unzip 加上 XML 编辑来修改现有文档、以及使用 pandoc 进行内容读取。该技能详细记录了使用 docx-js 库时的常见陷阱——包括页面尺寸、表格、列表、图像、分页以及目录(TOC)配置——帮助您避免文档格式错误。对于编辑操作,工作流程要求将 .docx 解压,合并碎片化的文本运行(run),编辑底层的 `word/document.xml`,然后重新打包;内置的验证脚本(通过 LibreOffice 转换为 PDF,然后使用 pdftoppm 进行渲染)可确保输出正确。该技能还涵盖了高级功能,如跟踪修订(插入/删除标记和带有 `w:author` 和 `w:date` 属性的段标记)、批注(通过一个辅助脚本自动创建六个交叉引用的 XML 文件)以及修正确认(接受/拒绝变更)。它支持 macOS(已安装 pandoc、LibreOffice、Poppler)和 Linux 平台,其中 npm 包 `docx` 已预先安装。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/anthropics/skills/tree/main/skills/docx

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

DOCX 创建、编辑和分析

.docx 文件是一个 XML 文件的 ZIP 压缩包。根据任务选择方法:

任务方法
创建新文档编写 docx (npm) 脚本——见下面的注意事项
编辑现有文档unzip → 编辑 word/document.xml → zip (docx-js 无法打开现有文件)
读取内容pandoc -t markdown file.docx

下面的脚本路径相对于此技能的目录。

使用 docx-js 创建——注意事项

docx 已预先安装——不要先运行 npm install;直接编写脚本并使用 require('docx')。仅当该 require 失败时:npm install docx。模型了解 API;以下是容易出错之处:

  • 页面尺寸默认为 A4。 要使用 US Letter,设置 page: { size: { width: 12240, height: 15840 } } (DXA;1440 = 1 英寸)。
  • 横向页面: 传入纵向尺寸和 orientation: PageOrientation.LANDSCAPE——docx-js 内部会自动交换宽高。
  • 表格需要双重宽度: 设置表格的 columnWidths 以及每个单元格的 width,两者均使用 WidthType.DXA(PERCENTAGE 在 Google Docs 中会出错)。列宽之和必须等于表格宽度。
  • 表格底纹: 使用 ShadingType.CLEAR,切勿使用 SOLID(会渲染为黑色)。
  • 列表: 切勿直接插入 •;应使用带有 LevelFormat.BULLET 的 numbering 配置。
  • ImageRun 需要 type: ("png", "jpg", ...)。
  • PageBreak 必须位于 Paragraph 内部。
  • 切勿使用 \n——应使用单独的 Paragraph 元素。
  • 目录 (TOC): 标题必须使用内置的 HeadingLevel.*;自定义标题样式需要设置 outlineLevel,否则不会出现在目录中。
  • 不要使用表格作为水平线——改用段落底部边框。
  • 点前导符/同一行右对齐: 使用 TextRun 内部的 PositionalTab (alignment: PositionalTabAlignment.RIGHT, leader: PositionalTabLeader.DOT),不要使用字面量的 . 或空格填充。

验证输出

在编写 .docx 之后,将其渲染并查看:

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。

unzip -q doc.docx -d unpacked/
find unpacked -type l -delete   # 移除符号链接条目——来自外部方的 docx 不可信
python scripts/merge_runs.py unpacked/   # 合并碎片化的运行,使文本可查找
# 原地编辑 unpacked/word/document.xml——不要重新格式化或美化打印
(cd unpacked && rm -f ../out.docx && zip -Xr ../out.docx .)
python scripts/office/validate.py out.docx --original doc.docx   # XSD 检查;--auto-repair 可修复常见问题
# 进行修订?添加 --author "<进行修订的名称>" 以检查每个编辑是否都被跟踪

Word 会将文本分散到多个 <w:r> 运行中(修订 ID、拼写检查标记),因此你在文档中看到的短语在 XML 中通常不是连续的字符串。merge_runs.py 合并 word/document.xml 中相邻且格式相同的运行,而不更改内容或渲染;它也直接接受 .docx 文件(python scripts/merge_runs.py doc.docx -o merged.docx)。

跟踪修订: 在修订时,使用 --author "<进行修订的名称>"(需要 --original)进行验证——它会报告任何你所更改但未包含在 <w:ins>/<w:del> 中的文本,这很容易无意中造成,并且在已接受视图中不可见。将运行包裹在带有 w:id、w:author、w:date 属性的 <w:ins>/<w:del> 中。在 <w:del> 内部,文本元素是 <w:delText>,而不是 <w:t>。一个被删除的段落标记(<w:pPr><w:rPr><w:del w:id=".." w:author=".." w:date=".."/></w:rPr></w:pPr>)意味着“将此段落合并到下一段”——因此直接删除一个段落就是该标记加上包围每个运行的 <w:del>。<w:del/> 必须位于 rPr 的其他子元素之前;它们的顺序由模式强制规定。

要生成接受所有跟踪修订的干净副本:python scripts/accept_changes.py in.docx out.docx。

接受一个被删除的段落标记应将此段落与下面的段落合并,因此所有运行都被删除的段落将消失。Word 会这样做;accept_changes.py 和 pandoc --track-changes=accept 并不总是能做到。两者都以相同的方式失败——它们会剥离已删除的文本,但留下空段落,当段落是自动编号时,它看起来像一个多余的空项目符号:

  • pandoc --track-changes=accept 从不会合并段落。
  • accept_changes.py(LibreOffice)可以正确合并,除非被删除的段落后面跟着一个空的间隔段落。

任何一个视图中的空项目符号都是该视图的产物,而不是文档的缺陷。请在 XML 中检查段落删除。

批注

批注需要六个交叉引用的文件。使用辅助程序——当你还将编辑 document.xml 时使用目录模式(节省一次解压/重新压缩的循环),否则使用 .docx 直接模式:

# 针对已解压的目录(放置标记时首选)
python scripts/comment.py unpacked/ "费用及支出上限过低"
python scripts/comment.py unpacked/ "同意" --parent 0

# 直接针对 .docx 文件
python scripts/comment.py contract.docx "此上限过低" -o annotated.docx

该脚本会写入 comments.xml、commentsExtended.xml、commentsIds.xml、commentsExtensible.xml、关系文件以及内容类型覆盖。批注 ID 会自动分配。然后它打印需要添加到 word/document.xml 的 <w:commentRangeStart>/<w:commentRangeEnd>/<w:commentReference> 代码片段,以便批注锚定到特定文本——在放置这些标记之前,批注存在但不可见。

依赖项

docx (npm,已预先安装——仅当 require('docx') 失败时才安装) · pandoc · LibreOffice (soffice) · pdftoppm (Poppler)

Individual skills in this repo

This repo contains 19 individual skills — each has its own dedicated page.

academy-guide

Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content.

algorithmic-art

Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists

anthropics/template-skill

Replace with description of the skill and when Claude should use it.

brand-guidelines

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.

canvas-design

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

claude-api

|-

discernment-nudge

After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals, or emails, estimates or projections, analysis or interpretation of data, factual claims they may rely on, or a multi-step argument — invoke this skill BEFORE finalizing your reply and then, if it applies, append 2-3 short follow-up questions, each tied to something specific in what you just produced, that help the user check key facts, probe the reasoning or assumptions, and notice missing context. Do this at most once per conversation. Skip it when the user asked a trivial how-to or simple lookup, wants a purely educational explanation, asked you only to format, convert, or assemble a file from content they provided, is writing code they will run, is doing creative writing or casual chat, or already asked you to double-check, cite, or review — the skill file explains these boundaries and the exact output format.

doc-coauthoring

Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.

frontend-design

Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.

internal-comms

A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).

mcp-builder

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

pdf

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.

pptx

Use this skill any time a .pptx or .potx 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 or .potx 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 (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.

skill-creator

Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill

slack-gif-creator

Knowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like

theme-factory

Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.

webapp-testing

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

web-artifacts-builder

Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX artifacts.

xlsx

Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.

相关技能