docxtpl for Openclaw

A powerful Python library that enables using Microsoft Word files as Jinja2 templates to generate dynamic .docx documents.

killgfat
v0.0.1
May 9, 2026
0
733
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install docxtpl

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install docxtpl using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is docxtpl?

The docxtpl skill bridges the gap between sophisticated document design and automated data population. By leveraging the python-docx library for reading and writing and Jinja2 for its robust templating engine, this tool allows developers to design complex layouts directly in Microsoft Word and inject Python variables at runtime. This approach maintains high-fidelity formatting that is often lost with other document generation methods.

As part of the Openclaw Skills ecosystem, docxtpl simplifies the creation of reports, invoices, and legal documents. It handles everything from simple string substitution to complex logic like conditional paragraphs, table row looping, and dynamic image insertion, making it an essential utility for automated document workflows.

docxtpl Use Cases

  • Automated Reporting: Generating clinical or financial reports from raw data streams.
  • Invoice Generation: Creating branded, professionally formatted invoices by looping through line items in a table.
  • Legal & HR Documentation: Producing personalized contracts, offer letters, or compliance documents based on specific employee or client data.
  • Batch Document Processing: Utilizing Openclaw Skills to convert CSV records into individual personalized .docx files for mass distribution.
  • Dynamic Media Insertion: Swapping placeholder images in headers or footers with real-time generated charts or signatures.

How docxtpl Works

  1. Template Design: You create a standard .docx file in Microsoft Word, inserting Jinja2 tags such as {{ var }} for text or {%p for x in list %} for repeating paragraphs.
  2. Template Loading: The docxtpl skill initializes the DocxTemplate class with the path to your designed file.
  3. Context Preparation: A Python dictionary (the context) is built containing all the data, logic, or RichText objects intended for the document.
  4. Rendering: The .render(context) method processes the Jinja2 tags within the Word XML structure, replacing them with the actual data.
  5. Persistence: The final document is saved to the file system, preserving all original Word styles and formatting.

docxtpl Setup

To get started with this component of Openclaw Skills, install the core package and optional subdocument support via pip:

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

You can also use the CLI interface for quick rendering tasks:

python -m docxtpl template.docx data.json output.docx

docxtpl Data Schema & Taxonomy

The skill organizes data primarily through a Context Dictionary and specialized Word Tags. The following table outlines the tag types available:

Tag Type Syntax Scope & Purpose
Inline String {{ var }} Basic variable display with standard formatting
Rich Text {{r var }} Renders RichText objects with multiple styles
Paragraph Logic {%p ... %} Controls full paragraphs for conditionals or loops
Table Row {%tr ... %} Iterates over rows within a Word table
Table Cell {% cellbg %} Dynamically sets background colors for table cells
Escaping `{{ var e }}`

docxtpl Advanced Features

  • RichText & Listing Classes: Create complex text strings with multiple colors, fonts, and sizes within a single variable, or preserve whitespace and newlines using the Listing class.
  • Subdocument Merging: Use tpl.new_subdoc(path) to dynamically include external Word documents as parts of your main template.
  • Media Replacement: Perform low-level replacement of images and embedded objects specifically in headers and footers where standard tags are restricted.
  • Batch Processing Scripts: Includes pre-built Python scripts for rendering documents from CSV files, JSON strings, or command-line key-value pairs.
  • Custom Jinja2 Environments: Pass custom filters and extensions to the rendering engine for advanced data manipulation during the document generation process.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*