← 返回 Skills 市场
killgfat

Docxtpl

作者 KGTAF · GitHub ↗ · v0.0.1 · MIT-0
cross-platform ⚠ suspicious
33
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install docxtpl
功能描述
Generate Word (.docx) documents from Jinja2 templates. Uses python-docx (read/write) + Jinja2 (template engine). Design templates in Microsoft Word, then pop...
使用说明 (SKILL.md)

docxtpl Skill

Use a .docx file as a Jinja2 template, then fill it with Python data at runtime.

Installation

pip install docxtpl
# For subdocuments support:
pip install "docxtpl[subdoc]"

Quick Start

from docxtpl import DocxTemplate

doc = DocxTemplate("my_template.docx")
context = {"name": "Alice", "department": "Cardiology"}
doc.render(context)
doc.save("output.docx")

Workflow:

  1. Design a .docx in Word with Jinja2 tags ({{ var }}, {%p if ... %})
  2. Load the template with DocxTemplate(path)
  3. Build a Python context dict
  4. Call doc.render(context) then doc.save(path)

Tag Reference

Tag Scope Purpose
{{ var }} inline string Display a variable
{{r var }} inline styled Display a RichText object
{%p ... %} paragraph Control full paragraphs (if/for)
{%tr ... %} table row Control table rows
{%tc ... %} table column Control table columns
{%r ... %} run Control styled runs
{%p if cond %} / {%p endif %} paragraph Conditional paragraph
{%p for x in list %} / {%p endfor %} paragraph Loop over paragraphs
{% colspan N %} table cell Horizontal cell spanning
{% hm %} table cell Horizontal merge in for-loop
{% vm %} table cell Vertical merge in for-loop
{% cellbg color %} table cell Set cell background color
{ #p comment #} paragraph Comment
{%- -%} text merge Merge split lines
{ _%, %_ }, { _{, }_ } escape Display literal {%, %}, {{, }}

Important: Always put spaces around delimiters: {{ var }} not {{var}}.

CLI Usage

python -m docxtpl template.docx data.json output.docx
python -m docxtpl -o template.docx data.json output.docx  # overwrite

Key Classes

  • DocxTemplate(path) — Load a .docx template. Methods: .render(context), .save(path), .get_undeclared_template_variables(context=None)
  • RichText(text, ...) / R(text) — Styled text with .add() for multi-style concatenation
  • InlineImage(tpl, img_path, width, height) — Dynamic image insertion (use Mm(), Inches(), or Pt() for dimensions)
  • Listing(text) — Escaped text preserving \ /\a/\f without losing style
  • RichTextParagraph() / RP() — Paragraph-level properties (use with {{p var }})
  • Subdoctpl.new_subdoc(path) to merge existing .docx files

Media Replacement

For headers/footers where dynamic tags aren't supported:

tpl.replace_pic("dummy.jpg", "real.jpg")      # pictures
tpl.replace_media("dummy.mp3", "real.mp3")     # any media
tpl.replace_embedded("dummy.docx", "real.docx") # embedded docs
tpl.replace_zipname("path/in/zip.xlsx", "real.xlsx") # raw zip entry

Escaping

By default, no auto-escaping. Use one of:

  • RichText for safe content
  • {{ var|e }} in template
  • escape("text") in Python context
  • tpl.render(context, autoescape=True)

Tips

  • \ → newline, \a → new paragraph, → tab, \f → page break (in strings and RichText)
  • To render a template multiple times, call tpl.reset_replacements() before each render() if using media replacements
  • Pass a custom jinja_env to render() for custom Jinja2 filters
  • Preview get_undeclared_template_variables() to warn about missing keys

📖 Full API reference: references/official-docs.md

CLI Scripts

Convenience scripts in scripts/ (use {baseDir}/scripts/ path):

# Render with inline key=value pairs
python scripts/docxtpl-render.py template.docx out.docx name="Alice" age="30"

# Render from JSON file
python scripts/docxtpl-render-json.py template.docx data.json out.docx

# Render from JSON string
python scripts/docxtpl-render.py template.docx out.docx --json '{"name":"Bob"}'

# List missing template variables
python scripts/docxtpl-list-vars.py template.docx

# Batch render from CSV (one .docx per row, named by id column)
python scripts/docxtpl-render-batch.py patients.csv ./reports/ template.docx \
  --id-column patient_id --suffix _report --summary
安全使用建议
Install only if you are comfortable with a local docx templating tool that reads templates/data and writes output files. Be especially careful with the batch CSV renderer: use trusted CSV files, avoid ID values containing slashes or '..', and prefer reviewing or fixing the script so generated files cannot escape the chosen output directory.
功能分析
Type: OpenClaw Skill Name: docxtpl Version: 0.0.1 The docxtpl skill bundle is a legitimate wrapper for the python-docx-template library, providing tools to generate Word documents from Jinja2 templates. The included Python scripts (e.g., docxtpl-render.py, docxtpl-render-batch.py) and documentation (SKILL.md) are well-structured, follow standard practices for CLI utilities, and show no signs of malicious intent, data exfiltration, or prompt injection.
能力评估
Purpose & Capability
The skill coherently provides docx templating helpers using docxtpl/Jinja2 and local file reads/writes, which matches the stated purpose.
Instruction Scope
The instructions disclose Jinja2 rendering and the lack of default auto-escaping; users should treat templates and input data as document-generation logic, not plain text.
Install Mechanism
The skill tells users to install the external PyPI package docxtpl, which is expected for this purpose, but the install is unpinned and there is no separate install spec.
Credentials
The batch renderer writes files based on a CSV column without constraining the resulting path to the requested output directory.
Persistence & Privilege
No credentials, background services, persistent agents, or elevated privileges are shown; persistence is limited to user-requested output .docx files.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install docxtpl
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /docxtpl 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.0.1
Initial release of docxtpl skill. - Generate Word (.docx) documents from Jinja2 templates using Python. - Supports dynamic variable rendering, conditional logic, loops, and styling in Word templates. - Provides CLI tools and Python API for rendering documents with data from Python, JSON, or CSV. - Includes utilities for image/media substitution and listing missing template variables. - Full tag and class reference provided for template design and advanced use cases.
元数据
Slug docxtpl
版本 0.0.1
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Docxtpl 是什么?

Generate Word (.docx) documents from Jinja2 templates. Uses python-docx (read/write) + Jinja2 (template engine). Design templates in Microsoft Word, then pop... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 33 次。

如何安装 Docxtpl?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install docxtpl」即可一键安装,无需额外配置。

Docxtpl 是免费的吗?

是的,Docxtpl 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Docxtpl 支持哪些平台?

Docxtpl 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Docxtpl?

由 KGTAF(@killgfat)开发并维护,当前版本 v0.0.1。

💬 留言讨论