Automatic creation of DOCX files from template using data from a CSV

from docxtpl import DocxTemplate

“yes we need you to write 102 workplans”

Me: *I’ll pretend to write them but sure I can automate it*

So began 2 days of reading up on docxtpl and fine tuning my Python code to generate 102 Word documents with pretty much identical information except for some site specific details such as:

Site, Model, Firmware

Other than this the files were identical, but there was much scope for errors if I had to manually copy and paste long firmware version names and drift off halfway through due to the boredom of it.

So how did I create these?

Answer : Python, docxtpl , Libre Office, and some Tea and biscuits….

tea-biscuits
Get a brew and then check out the video below :

The full code relies on “cnw.csv” and the “template.docx” being present

The template file is a standard word docx file, but with {stuff} in the braces where you want the eventual data to appear, and where ‘stuff’ is the name of a Column in the CSV file.

Create multiple docx files using Linux and Pyton

Docxtpl : generate as many word documents you want – all from 1 docx template

Updated video using Windows and Docxtpl with Python t create multiple DOCX file from a single template using Jinja2

Leave a Reply