Community程式設計與開發github.com

docx

建立、讀取、編輯與操作 Word 文件(.docx 與 .dotx 檔案)的技能。支援專業文件製作,包含目錄、標題與頁碼等格式。

docx 是什麼?

此技能專為需要處理 Word 文件(.docx 與 .dotx)的開發者或 AI 代理設計。它提供三種主要途徑:使用 docx(npm)套件從頭建立新文件;透過解壓縮 ZIP、編輯 `word/document.xml` 並重新封裝來修改現有文件;以及利用 Pandoc 讀取內容。支援的平台包括任何能執行 Node.js、Pandoc、LibreOffice 與 Poppler 工具的環境。技能文件中詳細說明了大量實務陷阱,例如 docx-js 無法開啟既有檔案、表格需設定雙重寬度、清單必須使用編號設定而非手動輸入符號、以及分頁符號必須置於段落內等。此外,還涵蓋了進階功能如修訂追蹤(含驗證腳本)、註解管理(透過輔助腳本處理六個關聯檔案)以及輸出驗證(轉為 PDF 再以影像方式檢視)。編輯流程中包含合併相鄰文字區塊的腳本(`merge_runs.py`),因為 Word 常將單一詞句分散在多個 `<w:r>` 中。對於修訂追蹤,特別強調使用 `--author` 參數來驗證所有修改是否確實包在 `<w:ins>` 或 `<w:del>` 標籤內,避免意外產生未追蹤的變更。

相容平台~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> 區塊中(因修訂編號、拼字檢查標記等),因此你在文件中看到的詞句,在 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 的其他子元素之前;它們的順序是由結構定義(schema)強制規定的。

若要產生一份接受所有修訂的乾淨副本: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.

相關技能