python-docx-template
python-docx-template copied to clipboard
Rowspan for tables?
Hello! Thanks to the conributers for a helpfull lib.
Is it possible to declare a rowspan in a dynamic table? Colspan works just fine so I assumed the rowspan tag should exist too but it seems it doesn't. Did a brief search of the source code. Found only the colspan function.
Not possible yet...
I figured out how to do this, but its definitely not through editing the file in MS/Libre Office.
- In short you have to unzip the docx file, then edit word/document.xml file.
- Find the beginning <w:tr> and ending </w:tr> that contains your row
- Put the {% for %} and {% endfor %} between around that.
However, when I update/save the file in Libre, it seemed to remove those tags - probably because they break the XML schema, so Libre is repairing them. Wondering if there is some way in OpenXML to maintain those tags between saves? For example, a comment tag in the XML? Maybe with ?
But either way, its a manual process and outside of the normal scope of building a template.
For anyone wondering, there's built-in way to do this since version 0.4.6.
Just use {% vm %}
tag to declare a rowspan.
See following examples for details: vertical_merge_tpl.docx vertical_merge.docx
https://github.com/tsy19900929/docxtpl_dynamic_vertical_merging