2

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')
mozway
  • 194,879
  • 13
  • 39
  • 75
Oussama He
  • 555
  • 1
  • 10
  • 31

1 Answers1

0

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

tamdo
  • 3
  • 1
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 27 '21 at 16:49