'Set text in bold with office open xml in python docx template
I have the following code that grabs a word template and fills the required values inside of it:
text = "<w:r><w:rPr><w:b/></w:rPr><w:t>Test Text</w:t></w:r><w:r><w:t> < /w:t> </w:r>"
context = {
"content": text
}
template = DocxTemplate("document.docx")
template.render(context)
template.save(filename)
I need to set to bold part of that text and when I apply that xml format, I get the following:
And when I try to change it to this:
text = "<w:r><w:rPr><w:b/></w:rPr><w:t>Test Text</w:t></w:r>"
the document has invalid format.
So, how can I set part of the text to bold correctly?
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

