WolfSuiteWolfXLWolfPPTWolfDocxWolfRender

WolfDocx - template population

Fill a Word template table with rows from Python

Start from the .docx template your team already formats, with a placeholder row such as {{item}} and {{amount}}. WolfDocx clones that row once per record, fills each cell, and writes a new document that keeps the row's widths, borders, and styles.

Repeat a placeholder row once per record

from wolfdocx.templates import author_template, discover_template_targets, parse_template_request

row = discover_template_targets(
    "invoice_template.docx", kind="table-row", target={"table": 1, "row": 2}
)
names = {"{{item}}": "item", "{{amount}}": "amount"}
report = author_template(parse_template_request({
    "source": "invoice_template.docx",
    "destination": "invoice.docx",
    "source_sha256": row["source_sha256"],
    "repeats": [{
        "kind": "table-row",
        "target": row["target"],
        "structure_fingerprint_sha256": row["structure_fingerprint_sha256"],
        "slots": [{**s, "name": names[s["expected_old_text"]]} for s in row["slots"]],
        "instances": [
            {"values": {"item": "Implementation", "amount": "12,000"}},
            {"values": {"item": "Support", "amount": "3,000"}},
        ],
    }],
}))
assert report.passed, report.code

An empty instances list removes the template row. Besides table rows, the same call can target a block of paragraphs and simple tables, a plain-text content control, or a native Word repeating section. Every selection is resolved against the unchanged source before anything is written.

When to use WolfDocx and when to use docxtpl or docx-mailmerge

  • Use docxtpl when the template is authored for Jinja2 tags with loops and conditionals, since it renders that template logic.
  • When the template is built from Word MERGEFIELD fields, use WolfDocx mail merge instead. This placeholder fill refuses templates whose selected rows contain fields.
  • Use WolfDocx when the template is an existing document with literal placeholder text, and each fill should be bound to that exact file and refused if the template changed.

Limitations

  • Merged or nested rows and tables, fields, tracked revisions, and comments inside the selection are refused.
  • Every record must supply a value for every named slot.
  • When a request is refused, an existing destination file stays untouched.
  • WolfDocx does not lay out pages and makes no general Word compatibility promise.

Get WolfDocx

WolfDocx Community is MIT-licensed and free, including commercial use. It edits existing .docx files in place in pure Python and does not render pages or convert to PDF. WolfDocx Commercial does not change those rights.

pip install wolfdocx

WolfDocx Commercial is an organization-scoped subscription. WolfDocx Community installs from public PyPI with pip install wolfdocx. WolfDocx Commercial installs from the authenticated WolfDocx package index with a per-purchase credential, issued on the checkout success page after payment and reissued through https://wolfxl.com/recover.

Review the scoped before-and-after memo files in the reporting walkthrough, or ask about your document before purchasing if compatibility is uncertain.

Related tasks