Official编程与开发github.com

docx

创建、读取、编辑或操作 Word 文档(.docx 文件)或 Word 模板(.dotx 文件)的技能。

docx 是什么?

该技能提供了一套完整的 Word 文档(.docx)操作方案,包括创建、编辑、读取和分析。创建新文档时,通过编写 docx (npm) 脚本来实现,并内置了多种常见陷阱的规避指南,如页面设置、表格宽度、列表、页眉页脚等。对于现有文档的编辑,采用先解压再编辑 XML、最后重新打包的方式,并提供了辅助脚本(如 `merge_runs.py`)来处理 Word 分裂文本运行的问题。读取文档时,推荐使用 pandoc 将 docx 转换为 markdown 格式。该技能还支持追踪修订(redlining)和评论,通过专门的 Python 脚本进行验证和操作,确保修改符合格式规范。输出结果可以通过 LibreOffice 转换为 PDF 进行可视化验证。

兼容平台~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 元素。
  • 目录: 标题必须使用内置的 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/   # 合并碎片化的 runs,使文本可查找
# 原地编辑 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:ins>/<w:del> 中,并附带 w:id、w:author、w:date 属性。在 <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 会自动分配。然后它会打印出 <w:commentRangeStart>/<w:commentRangeEnd>/<w:commentReference> 片段,需要添加到 word/document.xml 中,以便注释锚定到特定文本——在放置这些标记之前,注释存在但不可见。

依赖项

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 \

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 \

相关技能