Word 排版技能(统一版)
一、场景识别与路由
| 场景 | 识别特征 | 执行分支 |
|---|---|---|
| A · 学员手册 | 有课程大纲 + 知识点/提示词内容;说"学员手册""配套资料" | → 分支 A |
| B · 公文手册 | 受众为党政机关/高校/事业单位;说"公文""正式文件" | → 分支 B |
| C · 通用手册 | 其他内容排版需求 | → 分支 C(默认) |
二、启动前澄清(必做)
正式生成前,用 ask_user_input_v0 工具一次性提出以下问题:
Q1. 手册的主要使用方式?
A. 课堂现场配合讲师(留白填空为主)
B. 课后自学复习(内容完整自洽)
C. 工作中随时查阅(工具书风格)
D. 正式存档或对外呈现(公文/报告风格)
Q2. 内容呈现侧重?
A. 理论要点 + 说明(知识讲解型)
B. 步骤拆解 + 操作指引(实操型)
C. 场景案例 + 提示词模板(案例驱动型)
D. 综合以上多种形式
Q3. 特殊版块需要哪些?(可多选)
A. 章节引导语(每章开篇,左色条+浅红底)
B. 步骤流程块(1→2→3横向卡片)
C. 对比表格(多列对比)
D. 引用/金句(楷体缩进,上下细线)
E. 提示词模板框(学员手册专用)
三、统一设计规范
3.1 颜色系统(单色原则)
const RED = "8B1A1A"; // 唯一强调色,用于分割线/装饰/辅助元素
const WHITE = "FFFFFF";
const BLACK = "1A1A1A"; // 正文
const GRAY = "F5F5F5"; // 浅灰底色(表格交替行、步骤卡片)
const MGRAY = "888888"; // 辅助文字
const LGRAY = "DDDDDD"; // 细线/表格边框
const DKGRAY = "555555"; // 次要正文
严格单色原则:除正文黑色外,只使用 RED 及其深浅变体,不引入蓝、橙、绿等其他颜色。
3.2 页面规格
const PAGE_W = 11906; // A4 宽度 DXA
const PAGE_H = 16838; // A4 高度 DXA
const M_TOP = 1440;
const M_BOT = 1440;
const M_LEFT = 1800;
const M_RIGHT = 1800;
const CONTENT_W = PAGE_W - M_LEFT - M_RIGHT; // = 8306 DXA
3.3 工具函数(每次必须包含)
const bdr = (color, size = 4) => ({ style: BorderStyle.SINGLE, size, color });
const noBdr = () => ({ style: BorderStyle.NONE, size: 0, color: WHITE });
const noBdrs = () => ({
top: noBdr(), bottom: noBdr(), left: noBdr(), right: noBdr(),
insideH: noBdr(), insideV: noBdr()
});
const blank = (pt = 120) => new Paragraph({ children: [new TextRun("")], spacing: { before: 0, after: pt } });
const pageBreak = () => new Paragraph({ children: [new PageBreak()] });
四、封面规范(居中简洁版)
原则:纯文字全居中排版,只需要主标题、副标题、日期三项。全部居中对齐。
function makeCover(title, subtitle, dateStr) {
return [
blank(2400), // 顶部留白,让内容视觉上居中
// 主标题(大号加粗,主题红色)
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: title, color: RED, bold: true, size: 72, font: "Microsoft YaHei" })],
spacing: { before: 0, after: 200 },
}),
// 副标题
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: subtitle, color: DKGRAY, size: 28, font: "Microsoft YaHei" })],
spacing: { before: 0, after: 480 },
}),
// 红色装饰分割线
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: "", size: 4 })],
border: { bottom: { style: BorderStyle.SINGLE, size: 6, color: RED, space: 1 } },
spacing: { before: 0, after: 400 },
}),
// 日期
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: dateStr, color: MGRAY, size: 24, font: "Microsoft YaHei" })],
spacing: { before: 0, after: 0 },
}),
];
}
调用示例:
...makeCover(
"AI 提示词实战手册",
"从入门到企业级应用",
"2026 年 7 月"
),
五、组件代码规范(Word 实测验证,参数不要改动)
5.1 一级标题(带底边线,紧凑一体)
function h1(text) {
return new Paragraph({
children: [new TextRun({ text, color: RED, bold: true, size: 36, font: "Microsoft YaHei" })],
spacing: { before: 400, after: 200 },
indent: { left: 0 },
border: { bottom: { style: BorderStyle.SINGLE, size: 8, color: RED, space: 2 } },
});
}
// 注意:不再需要 h1Line(),底边线已集成到 h1 段落自身,更紧凑
// 标题与底线的间距由 spacing.after + border.space 共同控制
使用方式:
- 标题文字中自带序号前缀:h1("一、XXXX")
- 标题为红色加粗,段落底边自带红色横线作为分割
- 无底色色块,线与标题紧凑一体
5.2 二级标题
function h2(text) {
return new Paragraph({
children: [new TextRun({ text, color: RED, bold: true, size: 28, font: "Microsoft YaHei" })],
spacing: { before: 320, after: 140 },
});
}
编号格式写在 text 里:h2("1.1 提示词的核心要素"),无竖线无底色。
5.3 三级标题
function h3(text) {
return new Paragraph({
children: [new TextRun({ text, color: BLACK, bold: true, size: 24, font: "Microsoft YaHei" })],
spacing: { before: 200, after: 80 },
});
}
5.4 正文段落
function body(text) {
return new Paragraph({
alignment: AlignmentType.JUSTIFIED,
indent: { firstLine: 480 },
children: [new TextRun({ text, color: BLACK, size: 24, font: "Microsoft YaHei" })],
spacing: { before: 0, after: 140 },
});
}
5.5 章节引导语
// 每章开篇仅出现一次,紧跟在 h1 后面
function chapterIntro(text) {
return new Paragraph({
border: { left: { style: BorderStyle.SINGLE, size: 20, color: RED, space: 6 } },
shading: { fill: "FDF3F3", type: ShadingType.CLEAR },
indent: { left: 120, right: 0 }, // ← space:6 + left:120 组合已实测,不要改
spacing: { before: 0, after: 280 },
children: [new TextRun({ text, color: "5A2020", size: 22, font: "Microsoft YaHei" })],
});
}
关键注意:
- space: 6 — 竖线和文字之间的间距,不能为 0(贴太紧)也不能 > 8(缩进过多)
- indent: { left: 120 } — 最小缩进,文字与正文基本对齐
- 每章只出现一次,不可在正文中重复出现
5.6 引用 / 金句块
function quote(text, source = "") {
return new Paragraph({
border: {
top: bdr("E0E0E0", 4),
bottom: bdr("E0E0E0", 4),
},
indent: { left: 480, right: 240 },
spacing: { before: 240, after: 240 },
children: [
new TextRun({ text: "\u201C", color: "CCAAAA", size: 52, font: "Microsoft YaHei" }),
new TextRun({ text: " " + text, color: RED, size: 25, font: "Microsoft YaHei", italics: true }),
...(source ? [new TextRun({ text: ` ${source}`, color: MGRAY, size: 19, font: "Microsoft YaHei" })] : []),
],
});
}
5.7 步骤流程块
function stepsBlock(steps) {
const colW = Math.floor(CONTENT_W / steps.length);
const colWs = steps.map((_, i) =>
i === steps.length - 1 ? CONTENT_W - colW * (steps.length - 1) : colW
);
return [
new Paragraph({
children: [new TextRun({ text: "操作流程", color: MGRAY, size: 18, font: "Microsoft YaHei", bold: true })],
spacing: { before: 200, after: 100 },
}),
new Table({
width: { size: CONTENT_W, type: WidthType.DXA },
columnWidths: colWs,
borders: noBdrs(),
rows: [
new TableRow({
children: steps.map((s, i) => new TableCell({
borders: noBdrs(),
shading: { fill: RED, type: ShadingType.CLEAR },
width: { size: colWs[i], type: WidthType.DXA },
margins: { top: 60, bottom: 60, left: 60, right: 60 },
children: [new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: `${i + 1}`, color: WHITE, bold: true, size: 26, font: "Microsoft YaHei" })],
})]
}))
}),
new TableRow({
children: steps.map((s, i) => new TableCell({
borders: {
top: bdr(RED, 8),
bottom: bdr(LGRAY, 4),
left: bdr(LGRAY, 4),
right: bdr(LGRAY, 4),
},
shading: { fill: GRAY, type: ShadingType.CLEAR },
width: { size: colWs[i], type: WidthType.DXA },
margins: { top: 100, bottom: 100, left: 100, right: 100 },
children: [
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: s.title, color: BLACK, bold: true, size: 22, font: "Microsoft YaHei" })],
spacing: { after: 60 },
}),
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: s.desc, color: DKGRAY, size: 18, font: "Microsoft YaHei" })],
}),
]
}))
}),
]
}),
blank(160),
];
}
5.8 对比 / 信息表格
function makeTable(headers, rows, colWidths) {
return new Table({
width: { size: CONTENT_W, type: WidthType.DXA },
columnWidths: colWidths,
rows: [
new TableRow({
tableHeader: true,
children: headers.map((h, i) => new TableCell({
shading: { fill: i === 0 ? "333333" : RED, type: ShadingType.CLEAR },
borders: { top: bdr("999999",4), bottom: bdr("999999",4), left: bdr("999999",4), right: bdr("999999",4) },
width: { size: colWidths[i], type: WidthType.DXA },
margins: { top: 80, bottom: 80, left: 120, right: 120 },
children: [new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: h, color: WHITE, bold: true, size: 21, font: "Microsoft YaHei" })]
})]
}))
}),
...rows.map((row, ri) => new TableRow({
children: row.map((cell, ci) => new TableCell({
shading: { fill: ri % 2 === 0 ? WHITE : GRAY, type: ShadingType.CLEAR },
borders: { top: bdr(LGRAY,2), bottom: bdr(LGRAY,2), left: bdr(LGRAY,2), right: bdr(LGRAY,2) },
width: { size: colWidths[ci], type: WidthType.DXA },
margins: { top: 80, bottom: 80, left: 120, right: 120 },
children: [new Paragraph({
alignment: ci === 0 ? AlignmentType.CENTER : AlignmentType.JUSTIFIED,
children: [new TextRun({
text: cell,
color: ci === 0 ? DKGRAY : BLACK,
size: 20,
font: "Microsoft YaHei",
bold: ci === 0
})]
})]
}))
}))
]
});
}
5.9 页眉 / 页脚
function makeHeader(handbookName, subLabel) {
return new Header({
children: [new Paragraph({
border: { bottom: { style: BorderStyle.SINGLE, size: 8, color: RED, space: 4 } },
tabStops: [{ type: TabStopType.RIGHT, position: CONTENT_W }],
children: [
new TextRun({ text: handbookName, color: RED, bold: true, size: 20, font: "Microsoft YaHei" }),
new TextRun({ text: `\t${subLabel}`, color: "BBBBBB", size: 18, font: "Microsoft YaHei" }),
],
})]
});
}
function makeFooter(brandName) {
return new Footer({
children: [new Paragraph({
border: { top: { style: BorderStyle.SINGLE, size: 4, color: "ECECEC", space: 4 } },
tabStops: [{ type: TabStopType.RIGHT, position: CONTENT_W }],
children: [
new TextRun({ text: brandName, color: "CCCCCC", size: 17, font: "Microsoft YaHei" }),
new TextRun({ text: "\t— ", color: "AAAAAA", size: 19 }),
new TextRun({ children: [PageNumber.CURRENT], color: "AAAAAA", size: 19 }),
new TextRun({ text: " —", color: "AAAAAA", size: 19 }),
],
})]
});
}
5.10 文档组装模板
const doc = new Document({
styles: {
default: {
document: { run: { font: "Microsoft YaHei", size: 24, color: BLACK } }
}
},
sections: [{
properties: {
page: {
size: { width: PAGE_W, height: PAGE_H },
margin: { top: M_TOP, bottom: M_BOT, left: M_LEFT, right: M_RIGHT },
},
titlePage: true, // 封面不显示页眉页脚
},
headers: { default: makeHeader("手册名称", "副标签 · 品牌名") },
footers: { default: makeFooter("品牌名称") },
children: content,
}]
});
Packer.toBuffer(doc).then(buf => {
fs.writeFileSync('output.docx', buf); // 输出到当前工作目录(Windows/Linux 均适用)
console.log('Done:', buf.length, 'bytes');
});
六、版块使用克制原则
每次生成前必须遵守,这是本技能最核心的设计原则:
| 版块 | 使用上限 | 说明 |
|---|---|---|
| 章节引导语 | 每章 1 次 | 紧跟 h1,不在正文中重复 |
| 步骤流程块 | 全文 2-3 次 | 只用于真正有操作顺序的内容 |
| 引用/金句块 | 全文 2-4 次 | 只用于值得单独突出的核心观点 |
| 对比/信息表格 | 按需 | 有多维度比较时使用 |
| TIP / NOTE / KEY POINTS 框 | 禁止 | 已从本技能移除,改为正文段落表达 |
正文写作原则:
- 所有信息用流畅的段落承载,特殊版块只是点缀
- 每个段落 3-5 句,段间有逻辑递进
- 重要内容直接写进正文,不依赖框框来强调
七、分支 A · 学员手册专用
内容结构
封面页(makeCover)
课程导览(目录,三列表格)
Part 00 · 工具清单(makeTable + 说明段落)
Part 01~0N · 各模块
└── h1 + chapterIntro(引导语紧跟在h1底边线之后)
└── h2 + body(正文为主)
└── 按需:stepsBlock / quote / makeTable
└── 提示词模板(promptBox)
附录 · 提示词速查表
提示词模板框
function promptBox(label, content) {
return new Paragraph({
border: { left: { style: BorderStyle.SINGLE, size: 16, color: RED, space: 6 } },
shading: { fill: "FDF3F3", type: ShadingType.CLEAR },
indent: { left: 120, right: 0 },
spacing: { before: 160, after: 160 },
children: [
new TextRun({ text: `📌 ${label} `, color: RED, bold: true, size: 20, font: "Microsoft YaHei" }),
new TextRun({ text: content, color: "5A2020", size: 21, font: "Microsoft YaHei" }),
],
});
}
常用工具网址
| 工具 | 网址 | 说明 |
|---|---|---|
| 豆包 | doubao.com | 字节跳动,支持智能体 |
| DeepSeek | chat.deepseek.com | 深度推理 |
| 通义千问 | tongyi.aliyun.com | 阿里,长文本 |
| Kimi | kimi.moonshot.cn | 超长上下文 |
| 通义听悟 | tingwu.aliyun.com | 会议录音转写 |
| 秘塔AI搜索 | metaso.cn | 无广告精准搜索 |
| ima知识库 | ima.qq.com | 腾讯私有知识库 |
| 扣子/Coze | coze.cn / coze.com | 智能体平台 |
| 腾讯元宝 | yuanbao.tencent.com | 腾讯 |
八、分支 B · 公文手册
8.1 编号层级(中文公文惯例)
- 一级标题:一、二、三、(中文数字 + 顿号,写在文字前)
- 二级标题:(一)(二)(三)(全角括号,不加顿号)
- 三级标题:1. 2. 3.(阿拉伯数字 + 点号)
- 重要:一级标题必须用"一、二、三、"格式,不要用项目符号或装饰符号(◆●等)
8.2 字体模式切换
| 模式 | 默认字体 | 适用场景 |
|---|---|---|
| 企业培训(默认) | 微软雅黑(Microsoft YaHei) | 培训方案、课程大纲、企业手册 |
| 机关公文 | 仿宋(FangSong) | 党政机关红头文件、正式公文 |
用户未指定时默认使用微软雅黑。若用户明确提到"红头文件""正式公文""党政机关",切换为仿宋。
8.3 版块克制规则
- 正文首行缩进 2 字符(480 DXA)
- 减少引用块和步骤流程,以段落和编号要点为主
- 表格仅用于对比例举或速查数据,不应替代正常论述
- 正文段落统一两端对齐(JUSTIFIED),段间插入空行
8.4 要点排版(bulletB)
正文中的编号要点:序号+关键词加粗 + 说明文字不加粗,组合为一个段落:
function bulletB(boldPart, normalPart) {
return new Paragraph({
spacing: { before: 60, after: 180 },
children: [
new TextRun({ text: boldPart, bold: true, color: BLACK, size: 24, font: "Microsoft YaHei" }),
new TextRun({ text: normalPart, bold: false, color: BLACK, size: 24, font: "Microsoft YaHei" }),
]
});
}
// 示例:bulletB("1. 核心红线:", "涉密内容绝对禁止输入,内部敏感信息脱敏后方可使用。")
要点间必须有空行(通过段后间距 180 DXA 或 blank() 实现)。
8.5 内容撰写深度要求
公文手册应达到出版级内容深度:
- 段落为王:用连续的自然段落展开论述,每段讲透一个观点,不跳跃、不堆关键词
- 深度优先:每个知识点需包含"是什么 → 为什么 → 怎么做 → 常见误区"四个层次,不可只有结论没有推导
- 示例驱动:抽象概念后必须紧跟具体示例,让读者能对照理解
- 结构完整:章节间有逻辑递进,避免碎片化罗列
- 篇幅充足:核心章节每个知识点至少展开 2-3 个自然段
禁止做法:
- 用表格替代正常论述(一句话带过,读者看了也不会用)
- 用关键词堆砌代替段落(大纲式摘要而非书籍式展开)
8.6 表格使用准则
表格仅在以下场景使用:
- 公式/数据速查表(对照表、速查卡)
- 多项目横向对比(适用场景对照)
- 步骤流程表(时间/操作对照)
其他内容一律用段落 + 编号要点呈现。禁止用表格填充内容凑页数。
九、执行流程
Step 1 读取本 SKILL.md(已完成)
Step 2 docx 库用法以本 SKILL 中的组件代码为准(组件已实测验证,无需再查外部文档)
Step 3 ask_user_input_v0 提出澄清问题
Step 4 确定场景分支 / 版块组合 / 内容结构
Step 5 编写完整 Node.js 脚本(generate.js)
⚠ 直接复制本 SKILL 中的组件函数,参数不要自行修改
⚠ 遵守版块克制原则,TIP/NOTE/KEY POINTS 框禁止出现
Step 6 在当前工作目录运行 node generate.js(Windows 本机用受管 node:C:\Users\zc455\.workbuddy\binaries\node\versions\22.22.2-2\node.exe,docx 包已装于 binaries\node\workspace\node_modules,运行时设 NODE_PATH=该目录)
Step 7 验证产物:文件存在且 > 20KB(可用 node 读文件头校验 PK 签名)
Step 8 产物放在当前工作区 outputs/ 目录,路径供 present_files 使用
Step 9 present_files 呈现给用户
十、质量自检清单
- [ ] 封面:主标题红色,全居中,仅主标题 + 副标题 + 日期三项
- [ ] 封面:主标题红色大号加粗,副标题灰色,日期最下方浅灰
- [ ] h1:左对齐无缩进,红色加粗,序号
一、写进 text,段落自带底边红色分割线 - [ ] h1:无底色色块,无边线已集成到段落自身,紧凑无空隙
- [ ] h2:红色加粗,格式
1.1 XXXX,无竖线无底色 - [ ] chapterIntro:
space:6+indent:{left:120},每章仅出现一次 - [ ] 全文颜色:只用 RED(8B1A1A) 及其变体,无蓝/橙/绿
- [ ] TIP / NOTE / KEY POINTS:全文不出现
- [ ] 页眉:红色手册名 + Tab右对齐副标签 + 红色底线
- [ ] 页脚:灰色品牌名 + Tab右对齐「— N —」+ 浅灰顶线
- [ ] titlePage: true(封面无页眉页脚)
- [ ] 文件大小 > 20KB