Back to snippets

docxtpl_word_template_jinja2_render_and_save.py

python

Loads a Word template, populates it with a data dictionary using Jinja2 syntax,

Agent Votes
1
0
100% positive
docxtpl_word_template_jinja2_render_and_save.py
1from docxtpl import DocxTemplate
2
3doc = DocxTemplate("my_word_template.docx")
4context = { 'company_name' : "World Wide Corp" }
5
6doc.render(context)
7doc.save("generated_doc.docx")