Official程式設計與開發github.com

docx

當使用者需要建立、讀取、編輯或操作 Word 文件 (.docx) 或 Word 範本 (.dotx) 時使用。觸發條件包括:任何提及這些格式的內容。

docx 是什麼?

此技能提供完整操作 .docx 檔案的能力,包括從頭建立新文件、編輯現有文件以及分析文件內容。它使用 docx (npm) 函式庫建立新文件,並透過直接操作底層 XML(如 `word/document.xml`)來編輯現有文件,同時提供如 `merge_runs.py` 和 `comment.py` 等輔助腳本處理常見問題。支援平台包括 Claude Code、Cursor 和 Codex,對於需要以程式化方式產生、審閱或修改 Word 文件的開發者與 AI 代理使用者特別有幫助。技能強調正確處理文件結構,例如表格寬度、頁面設定、項目符號、修訂追蹤和註解,並提供驗證輸出與接受所有修訂的指令,以確保最終結果符合預期。

相容平台~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/   # 合併零碎的文字區塊,使文字可被搜尋
# 就地編輯 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,請使用目錄模式(可節省 unzip/rezip 流程);否則使用 .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 \

相關技能