Communityコーディング&開発github.com

docx

Word文書(.docx/.dotx)の作成、読み取り、編集、操作を実行します。レポートやテンプレートなどの作成に対応。

docx とは?

このスキルは、AIエージェントがWord文書(.docx/.dotx)をプログラムで作成、編集、解析するための包括的な機能を提供します。特に、docx-jsライブラリを用いた新規文書作成、XMLレベルでの既存文書編集、pandocによる内容読み取りをサポートします。docx-js使用時の注意点(用紙サイズ、表の幅設定、リスト、画像、ページ区切りなど)や、既存文書編集時のワークフロー(unzip→XML編集→再zip)、変更履歴やコメントの操作手順について詳しく説明しています。また、出力確認用のPythonスクリプトや検証ツールも含まれており、高品質な文書生成を実現します。

対応~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に質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

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レターの場合は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で一般的な問題を修正
# 変更履歴(redlining)? --author "<変更履歴を付けた名前>" を追加して、すべての編集が追跡されているか確認

Wordはテキストを多数の<w:r>ラン(リビジョンID、スペルチェックマーカー)に分割するため、文書上で見えるフレーズがXML上で連続した文字列として存在しないことがよくあります。merge_runs.pyは、word/document.xml内で隣接する同一フォーマットのランを、内容やレンダリングを変更せずに結合します。また、.docxを直接受け取ることもできます(python scripts/merge_runs.py doc.docx -o merged.docx)。

変更履歴(Tracked changes): redlining時には、--author "<変更履歴を付けた名前>"(--originalが必要)を指定して検証します — これにより、誤って変更履歴なしで変更したテキスト(承認ビューでは見えない)を報告します。ランを<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で確認してください。

コメント

コメントには6つの相互リンクされたファイルが必要です。ヘルパーを使用 — 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は自動的に割り当てられます。その後、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.

関連スキル