By Dr. Louay Chebib
https://github.com/Netuser-Py/PythonDocx
Standards: ‘WordML’, ‘Office Open XML’ and ‘Open XML’ by Microsoft.
https://python-docx.readthedocs.io/en/latest/index.html
Review of MS Word
Easy to Install
Sample Part 1
import docx
Create a blank word file in memory
Add headings
Add Table
Add Table Headings
Add Table Details
Add a page break
Open a Template/Form .docx file that you created in word
Merge this into doc_work
Save the file from memory
Sample Part 2
Use a template word file to create a non standard size page
Open a Template/Form .docx file that you created in word 4 x 6 inch form
list the main paragraph text (not the table text)
Load the paragraphs into a list
overwrite the contents of paragraphs
replace as needed
now look through the tables 0 & 1 and change paragraphs in each table
save doc
Sample Part 3
new doc_out document in memory for merge demo
merge work to doc_out
merge doc into doc_out. Note that somehow it follows the layout of the 4 x 6 template
Note: last document merged controls
we just merged doc_work then doc.
what happens if we change the order? try It!
Bonus pprint Sample
Print a docx file in the background using MS Word from inside Python
see: pprint_sample.py