Communitygithub.com

docx

用於建立、讀取、編輯或操作 Word 文件 (.docx) 與範本 (.dotx)。任何提及相關操作時皆可觸發此技能。

docx 是什麼?

此技能協助 AI 代理處理 Microsoft Word 的 .docx 與 .dotx 檔案。DOCX 本質上是一個包含 XML 檔案的 ZIP 壓縮檔,技能針對不同任務提供三種主要方法:使用預先安裝的 docx (npm) 套件建立新文件;透過解壓縮、編輯 word/document.xml 再重新壓縮的方式編輯現有文件;以及使用 pandoc 讀取內容。文件詳細列出了使用 docx-js 的常見陷阱,例如頁面尺寸設定、表格雙重寬度設定、清單使用編號設定而非直接輸入 • 符號,以及正確使用遮色片與分頁符號等。技能也包括驗證輸出流程(透過 soffice 與 pdftoppm 轉為 PDF 後進行視覺檢查)、合併分散的文字片段(merge_runs.py)、追蹤修訂驗證(確保每次編輯都有對應的 <w:ins>/<w:del> 標記)、註解處理(動態建立六個相關的 XML 檔案),以及接受所有追蹤修訂的清理功能。整體而言,此技能提供可靠的文件生成與操控能力,避免常見的格式錯誤。

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

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

DOCX 建立、編輯與分析

一個 .docx 檔案其實是 ZIP 壓縮檔,內含多個 XML 檔案。請依據任務選擇合適的方式:

任務方法
建立新文件撰寫 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 (在 Google Docs 中使用 PERCENTAGE 會出錯)。欄寬總和必須等於表格寬度。
  • 表格背景: 使用 ShadingType.CLEAR,絕對不要使用 SOLID (會渲染成黑色)。
  • 清單: 絕對不要直接插入 • 符號;應使用 numbering 設定搭配 LevelFormat.BULLET。
  • ImageRun 需要 type: (例如 "png"、"jpg" 等)。
  • PageBreak 必須放在 Paragraph 內部。
  • 絕對不要使用 \n — 請使用獨立的 Paragraph 元素。
  • 目錄: 標題必須使用內建的 HeadingLevel.*;自訂標題樣式需要設定 outlineLevel,否則不會出現在目錄中。
  • 不要使用表格當作水平線 — 改用段落底部框線。
  • 點狀引導 / 同行對齊: 在 TextRun 內部使用 PositionalTab (alignment: PositionalTabAlignment.RIGHT、leader: PositionalTabLeader.DOT),不要使用 literal . 或空格填充。

驗證輸出

寫好 .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: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 會自動指派。接著腳本會輸出要加入 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.

相關技能