{"skill":{"slug":"docx-template-strict","displayName":"Docx Template Strict","summary":"Strictly fill a DOCX template (preserving cover/headers/sections/styles) using placeholder tokens, with optional figures and references. For any task like: ‘...","description":"---\nname: docx-template-strict\ndescription: \"Strictly fill a DOCX template (preserving cover/headers/sections/styles) using placeholder tokens, with optional figures and references. For any task like: ‘use this Word template to format/fill papers and keep the template layout identical’.\"\nlicense: MIT\n---\n\n# docx-template-strict\n\n目的：把 `.docx` 当作“模板”来用，**完整保留**模板的封面、分节（sectPr）、页眉页脚、样式、下划线 run 结构、字体与布局；只在模板中指定的占位符位置填充文本/图片/参考文献。\n\n> 关键原则：**不要用 python-docx 重新生成段落结构**（这会破坏模板 run/sectPr）。\n> 本 skill 采用：`docx(zip) → XML 精确替换 → 写回 docx`。\n\n## 适用场景\n- “按某个 Word 模板格式提交作业/论文/报告，封面与排版必须和模板一致”。\n- 需要插图、图题、参考文献，同时保持模板视觉 1:1。\n\n## 输入要求（模板必须包含占位符）\n\n### 占位符格式\n- 统一：`{{TOKEN_NAME}}`\n- 必须是**连续字符串**，避免被 Word 拆成多个 run。\n\n### 常用占位符（建议）\n- `{{TITLE_CN}}` / `{{TITLE_EN}}`\n- `{{NAME_CN}}` / `{{NAME_EN}}`\n- `{{MAJOR}}` `{{CLASS}}` `{{STUDENT_ID}}`\n- `{{COURSE}}` `{{TEACHER}}` `{{DATE_CN}}`\n- `{{ABSTRACT_CN}}` `{{KEYWORDS_CN}}`\n- `{{ABSTRACT_EN}}` `{{KEYWORDS_EN}}`\n\n### 图占位符（段落级）\n每张图推荐 3 段占位符（各占一整段，且仅包含该 token）：\n- `{{FIG1}}`\n- `{{FIG1_CAPTION_CN}}`\n- `{{FIG1_CAPTION_EN}}`\n\n第二张图：`FIG2` 同理。\n\n### 参考文献占位符\n- 推荐整块替换：`{{REFERENCES}}`（多行文本，包含 `[1]...`）\n\n## 用法\n\n### 1) 填充模板生成 docx\n运行脚本：\n\n```bash\npython3 ~/.openclaw/skills/docx-template-strict/scripts/fill_template.py \\\n  --template \"/path/to/template.docx\" \\\n  --out \"/path/to/output.docx\" \\\n  --data \"/path/to/data.json\"\n```\n\n`data.json` 示例：\n```json\n{\n  \"TITLE_CN\": \"...\",\n  \"TITLE_EN\": \"...\",\n  \"NAME_CN\": \"林佩权\",\n  \"NAME_EN\": \"Lin Peiquan\",\n  \"ABSTRACT_CN\": \"...\",\n  \"ABSTRACT_EN\": \"...\",\n  \"KEYWORDS_CN\": \"...\",\n  \"KEYWORDS_EN\": \"...\",\n  \"REFERENCES\": \"[1] ...\\n[2] ...\\n\"\n}\n```\n\n### 2) 插图（可选）\n在 `data.json` 中提供：\n```json\n{\n  \"FIG1\": {\"path\": \"/path/to/fig1.png\"},\n  \"FIG2\": {\"path\": \"/path/to/fig2.jpg\"}\n}\n```\n脚本会：\n- 把 `{{FIG1}}` 所在段落替换为图片 drawing\n- 保留模板段落样式（对齐/缩进）\n\n## 输出 QA（脚本自动做）\n- 扫描是否仍存在 `{{...}}` 未替换 token\n- 检查模板分节数量（sectPr）是否被破坏（必须一致）\n- 检查 media 资源是否写入且 rels 指向有效\n\n## 注意事项 / 已知限制\n- 强依赖占位符：如果模板里没有 token，无法保证 1:1。\n- 若 Word/WPS 将 token 拆成多个 run：脚本可能无法识别（建议复制 token 时使用“仅保留文本”）。\n- PDF 导出不在本 skill 保真范围内：建议用本机 Word/WPS 导出 PDF，避免 LibreOffice 渲染漂移。\n","tags":{"latest":"1.0.0"},"stats":{"comments":0,"downloads":336,"installsAllTime":13,"installsCurrent":0,"stars":0,"versions":1},"createdAt":1778169930180,"updatedAt":1778492872010},"latestVersion":{"version":"1.0.0","createdAt":1778169930180,"changelog":"Initial release: Strictly fills DOCX templates by replacing placeholder tokens while fully preserving template layout and styles.\n\n- Replaces template tokens (e.g., {{TITLE_CN}}, {{FIG1}}) with data, including text, images, and references.\n- Maintains all original DOCX structures: cover, headers/footers, sections, styles, fonts, and layout.\n- Image placeholders are replaced at the paragraph level, preserving paragraph styles.\n- Provides quality checks to ensure tokens are replaced and template structure remains intact.\n- Requires explicit placeholders in the template; does not generate PDF output.","license":"MIT-0"},"metadata":null,"owner":{"handle":"lpq6","userId":"s177xez7z5cfebhpwpsrck8ps583zerd","displayName":"lpq6","image":"https://avatars.githubusercontent.com/u/113075650?v=4"},"moderation":null}