Communitygithub.com

docx

Word文書(.docx)やWordテンプレート(.dotx)の作成、読み取り、編集、操作を行うスキルです。「Word文書」「.docx」「.dotx」などのキーワードを含むリクエストで起動します。

docx とは?

このスキルは、AIエージェントがWord文書(.docx)をプログラム的に作成、編集、読み取り、分析するためのものです。新しい文書の作成にはnpmライブラリ `docx`(docx-js)を使用し、既存文書の編集には `unzip` → XML編集 → `zip` のフローを採用します。読み取りには `pandoc` を利用し、素早くマークダウン形式で内容を取得できます。トラブルシューティングとして、ページサイズのデフォルトがA4であること、表の幅設定の注意点、変更履歴(redlining)の扱い方など、多数の落とし穴(gotchas)について詳細なガイドを提供します。出力検証では、LibreOfficeでPDFへ変換後、`pdftoppm`で画像化して視覚確認します。コメントの追加には専用スクリプトを用い、6つの関連ファイルを自動生成します。このスキルは主にClaude CodeのようなAIエージェント向けに設計されており、開発タスクやドキュメント自動化に役立ちます。

対応✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/skills/docx

お気に入りの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 Letter にするには page: { size: { width: 12240, height: 15840 } } (DXA; 1440 = 1インチ) と設定します。
  • 横置き(Landscape): 縦置きの寸法と 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): 変更履歴をつける場合、--author "<変更履歴に記録した名前>" を指定して検証します(--original が必要) — これは、変更したにもかかわらず <w:ins> / <w:del> で囲まれていないテキストを報告します。これは誤って起こりやすく、承認済みビューでは見えません。ランを <w:ins> / <w:del> でラップし、w:id, w:author, w:date 属性を付けてください。<w:del> 内では、テキスト要素は <w:t> ではなく <w:delText> です。削除された段落記号(<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)


このスキルは Anthropic によって作成・保守されています。フロントマターのメタデータを除き、そのままベンダー配置されています。利用条件については LICENSE.txt を参照してください。

Individual skills in this repo

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

adaptyv

How to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.

aeon

This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.

alphagenome

Look up precomputed AlphaGenome Atlas effects for any GRCh38 single-nucleotide variant (AVI score with Phred and 18 SHAP feature attributions, plus raw and quantile scores for RNA-seq, DNase, ATAC, ChIP-TF, ChIP-histone, CAGE, PRO-cap, splicing, polyadenylation and contact-map tracks), score variants or scan windows on demand with the AlphaGenome model for human and mouse (variant scoring, in silico mutagenesis, REF-versus-ALT track prediction), and build Atlas website deep links. Use when the user mentions AlphaGenome, AlphaGenome Atlas, AVI or AlphaGenome Variant Impact, DeepMind variant effect prediction, or wants to prioritise or mechanistically interpret non-coding, regulatory, splicing, enhancer, promoter, or chromatin-accessibility effects of SNVs from a VCF, credible set, or region. Research use only; not a clinical tool.

analytical-method-validation

Plan, execute, and document validation, verification, and transfer of analytical procedures under the governing framework - ICH Q2(R2) and Q14, USP <1220>/<1225>/<1226>, ICH M10 bioanalytical, CLSI EP, or ISO/IEC 17025. Use for HPLC, LC-MS/MS, GC, CE, ICP-MS, dissolution, qNMR, qPCR, NIR, and ligand binding or cell-based assays whenever the question is whether a procedure is fit for its intended purpose. Triggers include

anndata

Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.

arbor

Autonomously improve a real artifact (code, training recipe, agent harness, data pipeline, prompt) against an objective and an evaluator, using Hypothesis Tree Refinement (HTR) from the Arbor paper. Use this whenever someone wants to iteratively optimize something over many experiments without overfitting — e.g.

arboreto

Infer gene regulatory networks (GRNs) from gene expression data using scalable algorithms (GRNBoost2, GENIE3). Use when analyzing transcriptomics data (bulk RNA-seq, single-cell RNA-seq) to identify transcription factor-target gene relationships and regulatory interactions. Supports distributed computation for large-scale datasets.

astropy

Core Python library for astronomy and astrophysics workflows that need Astropy APIs, including units/quantities, coordinates, FITS I/O, tables, time systems, WCS, and cosmology. Use when implementing or debugging astronomical data analysis code with Astropy.

autoskill

Observe the user

benchling-integration

Benchling Python SDK and REST API integration for registry entities, inventory, ELN entries, workflows, Benchling Apps, and Data Warehouse queries. Use when automating lab data with benchling-sdk or the v2 API.

bgpt-paper-search

Search scientific papers and retrieve structured experimental data extracted from full-text studies via the BGPT MCP server. Returns 25+ fields per paper including methods, results, sample sizes, quality scores, and conclusions. Use for literature reviews, evidence synthesis, and finding experimental details not available in abstracts alone.

bids

>

biopython

Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.

bioservices

Unified Python interface to 40+ bioinformatics services. Use when querying multiple databases (UniProt, KEGG, ChEMBL, Reactome) in a single workflow with consistent API. Best for cross-database analysis, ID mapping across services. For quick single-database lookups use gget; for sequence/file manipulation use biopython.

bulk-rnaseq

End-to-end bulk RNA-seq orchestrator — takes raw FASTQ reads through QC and trimming (FastQC, fastp/Trim Galore), alignment and quantification (STAR, Salmon, featureCounts), assembles a gene-level counts matrix, then hands off to differential expression (pydeseq2), pathway/GSEA enrichment (pathway-enrichment), and publication figures (scientific-visualization). Use whenever the user has bulk RNA-seq reads or quant output and wants a complete, reproducible differential-expression workflow — e.g.

cellxgene-census

Query the CZ CELLxGENE Census programmatically for versioned public single-cell and spatial transcriptomics data. Use when you need population-scale cell metadata, gene expression slices, Census summary counts, source H5AD URIs/downloads, embeddings, spatial Census data, or reference atlas comparisons across organisms, tissues, diseases, assays, and cell types. For analyzing your own local single-cell data use scanpy, anndata, or scvi-tools.

cirq

Google quantum computing framework. Use when targeting Google Quantum AI hardware, designing noise-aware circuits, or running quantum characterization experiments. Best for Google hardware, noise modeling, and low-level circuit design. For IBM hardware use qiskit; for quantum ML with autodiff use pennylane; for physics simulations use qutip.

citation-management

Comprehensive citation management for academic research. Search OpenAlex, PubMed, and Google Scholar for papers, extract accurate metadata, validate citations, and generate properly formatted BibTeX entries. This skill should be used when you need to find papers, verify citation information, convert DOIs to BibTeX, or ensure reference accuracy in scientific writing.

clinical-decision-support

Prepare and validate research-only clinical decision-support evaluation, evidence-profile, cohort, survival, biomarker/model, privacy, and governance artifacts. Use for aggregate or synthetic research documentation and traceability—not patient care or live clinical operation.

clinical-reports

Create safety-bounded draft structures and run local deterministic checks for clinical case, diagnostic, trial, safety, and aggregate research reports. Use only with synthetic, de-identified, or aggregate inputs and verified source-fact manifests; every output requires qualified review.

関連スキル