Communitygithub.com

docx

用于创建、编辑和操作 Word 文档(.docx)或模板(.dotx)文件的技能。

docx 是什么?

该技能是专门为处理 Microsoft Word 文档而设计的 AI 技能,支持创建、读取和编辑 .docx 文件,以及处理 .doc 文件转换。它主要通过三种方式实现:使用 docx (npm) 脚本从头创建文档、通过解压和编辑底层 XML 来修改已有文档、以及利用 pandoc 提取文本内容。该技能详细记录了 docx-js 库的使用陷阱,例如页面尺寸、表格宽度、列表格式、图片插入等,并提供了验证和修复脚本。对于复杂的文档操作,如编辑现有的 .docx 文件,该技能提供了完整的工作流程,包括解压、清理符号链接、合并格式碎片、编辑 XML 文件以及重新打包和验证。它还支持高级功能,如跟踪修订(带审核功能)、评论插入、以及删除与接受更改操作。整体上,该技能为开发者提供了一套完整的命令行工具链来处理 Word 文档,适合合同编辑、报告生成或文档自动化等场景。

兼容平台✓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 文件是 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。 如需美式信纸,请设置 page: { size: { width: 12240, height: 15840 } } (DXA;1440 = 1 英寸)。
  • **横向:**传入纵向尺寸并指定 orientation: PageOrientation.LANDSCAPE — docx-js 会在内部交换宽度/高度。
  • **表格需要双重宽度:**在表格上设置 columnWidths,并在每个单元格上设置 width,两者均使用 WidthType.DXA(在 Google Docs 中,PERCENTAGE 会失效)。列宽之和必须等于表格宽度。
  • **表格底纹:**使用 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 时使用目录模式(节省了解压/重新压缩周期),否则使用 .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)


该技能由 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.

相关技能