← Back to Skills Marketplace
lpq6

Docx Template Strict

by lpq6 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
43
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install docx-template-strict
Description
Strictly fill a DOCX template (preserving cover/headers/sections/styles) using placeholder tokens, with optional figures and references. For any task like: ‘...
README (SKILL.md)

docx-template-strict

目的:把 .docx 当作“模板”来用,完整保留模板的封面、分节(sectPr)、页眉页脚、样式、下划线 run 结构、字体与布局;只在模板中指定的占位符位置填充文本/图片/参考文献。

关键原则:不要用 python-docx 重新生成段落结构(这会破坏模板 run/sectPr)。 本 skill 采用:docx(zip) → XML 精确替换 → 写回 docx

适用场景

  • “按某个 Word 模板格式提交作业/论文/报告,封面与排版必须和模板一致”。
  • 需要插图、图题、参考文献,同时保持模板视觉 1:1。

输入要求(模板必须包含占位符)

占位符格式

  • 统一:{{TOKEN_NAME}}
  • 必须是连续字符串,避免被 Word 拆成多个 run。

常用占位符(建议)

  • {{TITLE_CN}} / {{TITLE_EN}}
  • {{NAME_CN}} / {{NAME_EN}}
  • {{MAJOR}} {{CLASS}} {{STUDENT_ID}}
  • {{COURSE}} {{TEACHER}} {{DATE_CN}}
  • {{ABSTRACT_CN}} {{KEYWORDS_CN}}
  • {{ABSTRACT_EN}} {{KEYWORDS_EN}}

图占位符(段落级)

每张图推荐 3 段占位符(各占一整段,且仅包含该 token):

  • {{FIG1}}
  • {{FIG1_CAPTION_CN}}
  • {{FIG1_CAPTION_EN}}

第二张图:FIG2 同理。

参考文献占位符

  • 推荐整块替换:{{REFERENCES}}(多行文本,包含 [1]...

用法

1) 填充模板生成 docx

运行脚本:

python3 ~/.openclaw/skills/docx-template-strict/scripts/fill_template.py \
  --template "/path/to/template.docx" \
  --out "/path/to/output.docx" \
  --data "/path/to/data.json"

data.json 示例:

{
  "TITLE_CN": "...",
  "TITLE_EN": "...",
  "NAME_CN": "林佩权",
  "NAME_EN": "Lin Peiquan",
  "ABSTRACT_CN": "...",
  "ABSTRACT_EN": "...",
  "KEYWORDS_CN": "...",
  "KEYWORDS_EN": "...",
  "REFERENCES": "[1] ...\
[2] ...\
"
}

2) 插图(可选)

data.json 中提供:

{
  "FIG1": {"path": "/path/to/fig1.png"},
  "FIG2": {"path": "/path/to/fig2.jpg"}
}

脚本会:

  • {{FIG1}} 所在段落替换为图片 drawing
  • 保留模板段落样式(对齐/缩进)

输出 QA(脚本自动做)

  • 扫描是否仍存在 {{...}} 未替换 token
  • 检查模板分节数量(sectPr)是否被破坏(必须一致)
  • 检查 media 资源是否写入且 rels 指向有效

注意事项 / 已知限制

  • 强依赖占位符:如果模板里没有 token,无法保证 1:1。
  • 若 Word/WPS 将 token 拆成多个 run:脚本可能无法识别(建议复制 token 时使用“仅保留文本”)。
  • PDF 导出不在本 skill 保真范围内:建议用本机 Word/WPS 导出 PDF,避免 LibreOffice 渲染漂移。
Usage Guidance
This skill is reasonable to install if you want local DOCX template filling. Before running it, verify the template, data JSON, image paths, and output path are the ones you intend, and only install any missing Python dependency from a trusted source.
Capability Analysis
Type: OpenClaw Skill Name: docx-template-strict Version: 1.0.0 The docx-template-strict skill is a utility for populating Word document templates while maintaining layout integrity. The core logic in scripts/fill_template.py uses zipfile and lxml to perform XML-based text and image replacement, which is consistent with its stated purpose. No indicators of data exfiltration, unauthorized execution, or malicious intent were found.
Capability Assessment
Purpose & Capability
The SKILL.md purpose is to fill DOCX placeholders while preserving template layout, and the included script implements local DOCX XML token replacement and optional image embedding.
Instruction Scope
The documented workflow is user-directed and does not instruct the agent to override user intent, bypass review, or perform unrelated actions.
Install Mechanism
There is no install spec, but the workflow relies on running Python and the script imports lxml, so dependency availability is not fully declared.
Credentials
The script reads and writes user-specified local document, JSON, image, and output paths, which is proportionate to DOCX templating but should be limited to intended files.
Persistence & Privilege
The artifacts show no credentials, privileged account access, background process, persistent memory, or continuing autonomous behavior.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install docx-template-strict
  3. After installation, invoke the skill by name or use /docx-template-strict
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
Initial release: Strictly fills DOCX templates by replacing placeholder tokens while fully preserving template layout and styles. - Replaces template tokens (e.g., {{TITLE_CN}}, {{FIG1}}) with data, including text, images, and references. - Maintains all original DOCX structures: cover, headers/footers, sections, styles, fonts, and layout. - Image placeholders are replaced at the paragraph level, preserving paragraph styles. - Provides quality checks to ensure tokens are replaced and template structure remains intact. - Requires explicit placeholders in the template; does not generate PDF output.
Metadata
Slug docx-template-strict
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is Docx Template Strict?

Strictly fill a DOCX template (preserving cover/headers/sections/styles) using placeholder tokens, with optional figures and references. For any task like: ‘... It is an AI Agent Skill for Claude Code / OpenClaw, with 43 downloads so far.

How do I install Docx Template Strict?

Run "/install docx-template-strict" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Docx Template Strict free?

Yes, Docx Template Strict is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Docx Template Strict support?

Docx Template Strict is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Docx Template Strict?

It is built and maintained by lpq6 (@lpq6); the current version is v1.0.0.

💬 Comments