I'm using python module docxtpl
to print data inside a docx template written with jinja2
.
Works great so far but i need to render in the docx some simple HTML like this:
<h2>Some title</h2>
<h4>Lorem ipsum <strong>dolor sit amet</strong>, consectetur adipisicing elit. Possimus, aliquam,
minima fugiat placeat provident optio nam reiciendis eius beatae quibusdam!</h4>
<p style="font-size: 18px;">The text is derived from Cicero's De Finibus Bonorum et Malorum (On the Ends of Goods
and Evils, or alternatively [About] The Purposes of Good and Evil). The original passage began: Neque porro
quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit (Translation: "Neither is
there <del>anyone</del> who loves grief itself since it is grief and thus wants to obtain it").</p>
<table class="table">
<tbody>
<tr>
<td>Test</td>
<td>Test1</td>
<td>Test2</td>
<td>Test3</td>
</tr>
<tr>
<td>Lorem</td>
<td>Lorem1</td>
<td>Lorem2</td>
<td>Lorem3</td>
</tr>
<tr>
<td>Ipsum</td>
<td>Ipsum1</td>
<td>Ipsum2</td>
<td>Ipsum3</td>
</tr>
</tbody>
</table>
Unfortunately I can't use RichText()
from docxtpl
to render tables and other html stuff.
I tried to come up with some solutions but I want to understand if there are better ways besides, for example, merge one docx generated from html usign htmldocx
with the one generated using docxtpl
or get the content with python-docx
module from one docx and insert it into the other.
In the worst case scenario, I am also willing to switch to JavaScript/BASH.