docxtpl Formatting lost when using subdoc()

Viewed 208

I have a DOCX template and I want to insert a sub document into it using the {{p }} tag, it works fine for now except that some formattings are lost. In the original document (sub_doc.docx), the title of the table is italic, centered, the size of the main font in the table 10, in the result file the title lost the italic and centered formatting.

How can I keep the formatting when inserting the sub document?

from docxtpl import DocxTemplate
tpl = DocxTemplate('tpl.docx')
sd = tpl.new_subdoc('sub_doc.docx')
context = {
'sd' : sd,
}
tpl.render(context)
tpl.save('result.docx')
1 Answers

i have faced this issue , until i read and understand how styles works in python docx . if you want to maintain your style , create style and put it in your template

Related