Word DOCX From Template | Python (2021 Version)
Dr Pi
Over a year ago I was asked to create 100+ almost identical word documents as "workplans" for my day job (They did not know I use Python to get things done). Writing multiple word documents and copy and pasting location, date, and contact details from a CSV was not what I had in mind.
Although I was a senior network engineer my boss seemed to think I would enjoy this highly repetitive task. I said it would take days, in the end it took about an hour to write the code and 5 seconds to generate 150 word documents (DOCX).
Automating the creation of these almost identical word documents was made possible with Python, docxtpl, and 1x word 'template' - (which was essentially a word doc with curly braces around the bits that are unique within the document).
I never expected the original video to be so popular, so I have remade it, using Windows, with newer and hopefully clearer explanations, and a full csv source file.
If you like this tutorial, or if it has saved you hours of your life please let me know as automating repetitive tasks with Python is very pleasing. It's the ultimate 'revenge' when an employer expects you to sit there and do it manually!
► The code here is written in Windows as opposed to Ubuntu in my earlier version of this video seen here : https://youtu.be/uVPc9As7Kkw
Seeing as I was rewriting it I thought I'd do it for M$ Windows.
► If you use Mac, or Linux, you'll need to edit the file path syntax to suit.
► If you don't have M$ Office then "Libre" or "Open" Office will work just the same.
Thanks for watching!
-- chapter timings --
0:00 Introduction 01:00 pip instal docxtpl 04:07 Starting code 07:31 The CSV values for the Jinja placeholders 12:26 split the row to get individual values 16:45 149 word documents in 5 seonnds
👍 Become a patron 👍 🌏 https://www.patreon.com/drpi
Buy Dr Pi a coffee (or Tea) ☕ https://www.buymeacoffee.com/DrPi ☕
Visit redandgreen blog for more Tutorials
🌏 http://redandgreen.co.uk/about/blog/
Subscribe to the YouTube Channel
🌏 https://www.youtube.com/c/DrPiCode
Follow on Twitter - to get notified of new videos
Proxies
If you need a good, easy to use proxy, I was recommended this one, and having used ScraperAPI for a while I can vouch for them. If you were going to sign up anyway, then maybe you would be kind enough to use the link and the coupon code below?
You can also do a full working trial first as well, (unlike some other companies). The trial ... https://www.youtube.com/watch?v=_jGVv_rvla8
115930962 Bytes