python-docx-template icon indicating copy to clipboard operation
python-docx-template copied to clipboard

Rowspan for tables?

Open sancau opened this issue 8 years ago • 4 comments

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.

sancau avatar Jan 21 '17 18:01 sancau

Not possible yet...

elapouya avatar Feb 14 '17 10:02 elapouya

I figured out how to do this, but its definitely not through editing the file in MS/Libre Office.

  1. In short you have to unzip the docx file, then edit word/document.xml file.
  2. Find the beginning <w:tr> and ending </w:tr> that contains your row
  3. 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.

khanzf avatar Jul 31 '17 04:07 khanzf

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

nikitagashkov avatar Aug 30 '18 09:08 nikitagashkov

https://github.com/tsy19900929/docxtpl_dynamic_vertical_merging test1

tsy19900929 avatar Nov 04 '22 05:11 tsy19900929