elapouya / python-docx-template

Use a docx as a jinja2 template
GNU Lesser General Public License v2.1
2k stars 388 forks source link

question on creating complex vertical merged tab? #104

Open retsyo opened 6 years ago

retsyo commented 6 years ago

in my real work situation, I have to create a complex tab which you can read in the attachment

so, is there any way to implement it in python-docx-template?

in my demo docx file, there are only for categories(Book, DVD, Milk and Bag), but in fact I have many tables which has different numbers of categories, and varing number goods in every category.

category.docx

elapouya commented 6 years ago

I put your request to the enhancement wish list...

FlorenceMei commented 4 years ago

Hi, how is it going with this enhancement? i have a similar table to create and I realized that jinja style template just doesn't accept any of my tries. It seems that nested FOR loops in one table is not possible. (see my examples) It also tried to correct the merging with docx but no luck... Tests_docx_tables.docx

Thanks in advance for improving this very promising package!

elapouya commented 4 years ago

it is better to transform

gauche = [[G11,G12,G13],[G21,G22,G23]]
droite = [[D11,D12,D13],[D21,D22,D23]]

into :

lignes = [[G11,G12,G13,D11,D12,D13],[G21,G22,G23,D21,D22,D23]]

So only one loop by row is needed.

FlorenceMei commented 4 years ago

Yes, I did it that way only to test if it is possible to align several loops next to each other, but apparently not. Therefore, I would like to know if there is another way to write the second table in my docx file (the table I would like to have as result). It is a very similar problem of complex tables as proposed in the first post.

retsyo commented 4 years ago

Finally, I have to launch MsWord via win32com, then merge the cells by writing python code.

I do expect there will be an easy way without opening MsWord

tsy19900929 commented 1 year ago

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