# Docx Cn

> 生成 .docx(docx-js)——Node 实现、中文优先、研究汇报向。内置 Node 运行法 / 共享依赖 NODE_PATH 技巧、中文字体坑、navy 学术配色、结果表(Rel/Gen/Loc/Avg 最佳值标红)模板、以及 Word 排版踩坑（标题/表格/列表/右对齐点引导符/分页/图片）。触发：做 Word / 报告 / 文档 / .docx，尤其涉及中文、实验结果表、指标、中英混排。

- **Type:** Skill
- **Install:** `agentstack add skill-ssssliug-claude-skill-docx-cn-claude-skill-docx-cn`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [ssssliug](https://agentstack.voostack.com/s/ssssliug)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [ssssliug](https://github.com/ssssliug)
- **Source:** https://github.com/ssssliug/claude-skill-docx-cn

## Install

```sh
agentstack add skill-ssssliug-claude-skill-docx-cn-claude-skill-docx-cn
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Word 文档生成（Node · 中文 · 研究向）

面向 Node-only 环境（**无 Python / LibreOffice / pandoc**，在 Windows + Node v24 上验证过；macOS / Linux 同理）。`.docx` 用 [`docx`](https://github.com/dolanmiu/docx)（npm 包名 `docx`，即 docx-js）。**只做创建**——转 PDF / 缩略图 / schema 校验等 QA 本机跑不了（要视觉预览需另装 LibreOffice）。

官方 `~/.claude/skills/docx`（默认停用，文件仍在）有更全的踩坑表与 Python 脚本（校验 / 缩略图 / 模板编辑 / tracked changes / comments）。遇到复杂或排错场景，可手动 `cat ~/.claude/skills/docx/SKILL.md` 当字典查——它不自动加载，但内容在。配套 PPT 技能见 `pptx-cn`。

## 运行（两种方式任选）

**方式 A · 本仓库装依赖（推荐，跨平台）**：仓库根 `package.json` 已列好依赖，`npm install` 后直接跑：

```bash
npm install
node templates/results_docx.js out.docx   # 输出路径可中文
```

**方式 B · 共享依赖 + NODE_PATH（Windows / Git Bash 特有技巧）**：把所有 skill 的 node_modules 集中放一处（如 `~/.claude/skills-deps/node_modules`，含 `docx`），脚本里直接 `require()`、不必每个仓库各装一份。node 是原生 Windows 程序、**不认 MSYS 的 `~` / `/tmp` 路径**，必须 cygpath + NODE_PATH：

```bash
NODE_PATH=$(cygpath -w ~/.claude/skills-deps/node_modules) node 脚本.js
```

输出用完整 Windows 路径 `C:/.../名.docx`，中文路径 OK。

---

## Word (docx-js)

```js
const {Document,Packer,Paragraph,TextRun,HeadingLevel,Table,TableRow,TableCell,WidthType,ShadingType,AlignmentType,PageOrientation,PositionalTab,PositionalTabAlignment,PositionalTabLeader} = require('docx');
```

- 页面默认 A4；US Letter：`page:{size:{width:12240,height:15840}}`（DXA，1440=1″）；横屏传纵向尺寸 + `orientation:PageOrientation.LANDSCAPE`。
- **中文**：每个 `TextRun` 都带 `font:'Microsoft YaHei'`，否则默认 Calibri 掉中文；省事可在 `styles.default.document.run.font` 设一次默认字体、单处再覆盖。
- 标题用 `HeadingLevel.HEADING_1/2`（目录依赖它；自定义样式需设 `outlineLevel`）。
- 表格：表级 `columnWidths` + **每格 `width`**(DXA) 都要设（`PERCENTAGE` 在 Google Docs 会坏）；列宽之和等于表宽。底纹用 `ShadingType.CLEAR`，**别用 `SOLID`**（渲染成黑）。
- 列表用 `numbering` 配 `LevelFormat.BULLET`，别手敲 `•`。
- `ImageRun` 必须带 `type:`（`"png"` / `"jpg"` …）。
- **别用 `\n`**，用多个 `Paragraph`；`PageBreak` 必须包在 `Paragraph` 里。
- 同行右对齐 + 点引导符：用 `PositionalTab`（`alignment:PositionalTabAlignment.RIGHT`，`leader:PositionalTabLeader.DOT`），别手敲 `.` 或空格补。
- 输出：`Packer.toBuffer(doc).then(b => fs.writeFileSync('out.docx', b))`。

### 结果表（每列最佳值标红）
研究汇报关键是**每列最佳值加粗标红**。别手敲——见 `templates/results_docx.js`：先 `num.forEach(k => best[k] = Math.max(...rows.map(r => r[k])))` 找每列 max，再在生成单元格时 `isBest = Math.abs(r[k]-best[k]) < 1e-6` 决定 `bold + color`。表头底纹用 navy `1F3A5F` 配白字，自己方法那行用浅底 `F4F6F7` 高亮。

模板：`templates/results_docx.js`（标题 + 段落 + 结果表，最佳值标红）。

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [ssssliug](https://github.com/ssssliug)
- **Source:** [ssssliug/claude-skill-docx-cn](https://github.com/ssssliug/claude-skill-docx-cn)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** yes
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-ssssliug-claude-skill-docx-cn-claude-skill-docx-cn
- Seller: https://agentstack.voostack.com/s/ssssliug
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
