Automating Word Documents from Excel Using Python | โ€˜docxtplโ€™ Tutorial

preview_player
ะŸะพะบะฐะทะฐั‚ัŒ ะพะฟะธัะฐะฝะธะต

๐——๐—˜๐—ฆ๐—–๐—ฅ๐—œ๐—ฃ๐—ง๐—œ๐—ข๐—ก
โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€
Did you know you can use Python code to dynamically create Word Documents? For this tutorial, we will be using the Python libraries โ€˜xlwingsโ€™ & โ€˜docxtplโ€™ to automate Word. In particular, we will be writing values from Excel to Word by using Python.

Download all the files from the tutorial:

๐—ง๐—ข๐—ข๐—Ÿ๐—ฆ ๐—”๐—ก๐—— ๐—ฅ๐—˜๐—ฆ๐—ข๐—จ๐—ฅ๐—–๐—˜๐—ฆ
โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€

๐—–๐—ข๐—ก๐—ก๐—˜๐—–๐—ง ๐—ช๐—œ๐—ง๐—› ๐— ๐—˜
โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€

โ˜• ๐—•๐˜‚๐˜† ๐—บ๐—ฒ ๐—ฎ ๐—ฐ๐—ผ๐—ณ๐—ณ๐—ฒ๐—ฒ?
ะ ะตะบะพะผะตะฝะดะฐั†ะธะธ ะฟะพ ั‚ะตะผะต
ะšะพะผะผะตะฝั‚ะฐั€ะธะธ
ะะฒั‚ะพั€

Very good, as usual ! I just love the fact that you don't need to be a profesionnal programmer to follow your tutorials. Really accessible with a basic knowledge.

corentindurand
ะะฒั‚ะพั€

Clear and concise. Delivers results and contains plenty of explanation to enable the viewer to adapt to their own project. Thank you for an excellent tutorial.

elsheep
ะะฒั‚ะพั€


Error

Traceback (most recent call last):

File "<string>", line 1, in <module>

File line 7, in <module>

os.chdir(sys.path[0])

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: ''



Press Ctrl+C to copy this message to the clipboard.



What should I do now? Thanks in advance!

yossialmogmaman
ะะฒั‚ะพั€

Dude, since i started watch your videos, my desire to learn python has grown.Thanks!

erickgutierrez
ะะฒั‚ะพั€

Your video solved half of my problems!

Now I need to think of a way to convert the data from the excel file to a word file whenever a new entry is added to the excel file.

I thought about using python-docx, but I would need to make the template ready for all possible entries in my csv file.

Gosh I have no idea how to proceed lol

Thanks for your work!!!!

victorsartor
ะะฒั‚ะพั€

For anyone having problems getting your samplecall macro to run, you might need to run the following command in your terminal "xlwings addin install"

matthewtaylor
ะะฒั‚ะพั€

This is very helpful, i would like to thank you. Please could you make another video on how to make a python script that draw a netwrok architecture or a network diagram and generate a visio file ? thank you.

zouhairsouam
ะะฒั‚ะพั€

Wow, exactly what I was looking for. It's straight to the point and easy to understand. Can you show how we would have a dynamic sentence based on the number we import from Excel? e.g. Sales on {{this period}} was {{sales}} which is {{more/less}} than {{prev period}} for {{an increase/a decrease}} of {{sales/prev sales-1}}%.

cryptomugen
ะะฒั‚ะพั€

Thank you again for your very helpful tutorial. I wanted tocomment that I was having difficulty getting the images to show up in MS Word. In case anyone else is also not getting the images to show up, I had to add the name of my placeholder value to the Alt Text parameter for that particular picture in the MS Word Template. Just go to the image placeholder picture in MS Word and right click on it to open the expanded menu, click on the option 'Edit Alt Text' and type in the image placeholder name (like Placeholder_A.png) - then exit the sidebar by clicking the 'X' Do NOT click on the button 'Generate alt text for me' -- it will do that with your tag when you close the menu.

cindyb
ะะฒั‚ะพั€

Muchas gracias, espectacular, muy agradecido, deseaaba consulta que contiene la macro Samplecall

josea.bocanegra
ะะฒั‚ะพั€

Hi, The document is created when I run the Python file. However it doesn't CREATE document when I click the button.

I include printing something like 'Bye Xkwings'. So it works. But the document is not created. Please help

jhanvivadher
ะะฒั‚ะพั€

I have issues to execute this instruction at the CMD window "xlwings quickstart word-automation --standalone" it tells me that the command "xlwings" is not recognizable as an external command internal and/or external

SaulEduardoo
ะะฒั‚ะพั€

Thank you so much, i could easily follow along the tutorial and help automate a tidious task my father has to do eveytime.

risshirajsen
ะะฒั‚ะพั€

Very interesting... I am trying to figure out how to automate a word document/pdf upon email receipt, as well as have that newly created word document/pdf emailed after creation.

wadspo
ะะฒั‚ะพั€

Thank you very much Sir! Your tutorial are very helpful and matched well with my work environment. Subscribed.

rty
ะะฒั‚ะพั€

good tut, try to tell us. How did we find and replace text?

elbadrey
ะะฒั‚ะพั€

Absolutely loved your video!!! Just one thing I need to know.

When declaring the context dictionary, is there some way I can store the numbers in the same type as given in excel?
Example:
1) if I use numbers=int while declaring the context dictionary, I can't work with specific values needing decimal precision (For example, mass of an electron). So how can I make python insert the exact same number as in excel?

rishanchaube
ะะฒั‚ะพั€


Error

Traceback (most recent call last):

File "<string>", line 1, in <module>

File "C:\Users\chitt\OneDrive\desktop\word_automation\word_automation.py", line 10, in <module>

os.chdir(sys.path[0])

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: ''



Press Ctrl+C to copy this message to the clipboard.

OK

please help me with this while im pressing the update word document button it is showing like this

manipalreddy
ะะฒั‚ะพั€

Hi, extremely helpful tutorial. How does one go about doing this if the table has multiple columns? Eg Parameter | Start | Average | Failure| Where Start, Average, and failure have values, and the parameter is the actual "product name" in this case.
The table in my word document is structured in the same way. Also, there are multiple tables on my first sheet. Thank you for your assistance with this tutorial. When working in the xlwings Excel file, the excel file closes as soon as I click the button.

JITISH
ะะฒั‚ะพั€

Hey, how could we add the rendered word file created using docxtpl into an existing word file.

Hex-Scholar