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.codeAn 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.
- Use docx-mailmerge when the template is built from Word MERGEFIELD fields. WolfDocx 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 Commercial is an organization-scoped subscription. Commercial package access uses the authenticated distribution channel. The package credential is issued on the checkout success page after payment and can be reissued through https://wolfxl.com/recover. There is no public free package.
Review the scoped before-and-after memo files in the reporting walkthrough, or ask about your document before purchasing if compatibility is uncertain.