I would like to edit .docx
documents using Python and more importantly I need it to be able to allow me to write subscripts like 2x in Python.
I have tried the docx
module but I can't seem to find out how to write subscripts.
I would like to edit .docx
documents using Python and more importantly I need it to be able to allow me to write subscripts like 2x in Python.
I have tried the docx
module but I can't seem to find out how to write subscripts.
If you are trying to write subscripts, try using the "stringified" form, so to speak:
>>> print '2\xe2\x82\x93'
2ₓ
>>>
You can use the XML representation of a subscript, eg:
<w:p>
<w:pPr>
<w:pStyle w:val="Normal"/>
<w:rPr>
<w:shd w:fill="auto" w:val="clear"/>
<w:vertAlign w:val="subscript"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr/>
<w:t>2</w:t>
</w:r>
<w:r>
<w:rPr>
<w:shd w:fill="auto" w:val="clear"/>
<w:vertAlign w:val="subscript"/>
</w:rPr>
<w:t>x</w:t>
</w:r>
</w:p>
To insert that xml inside your doc, you can use the docxtemplater cli (it is written in Node) https://github.com/open-xml-templating/docxtemplater (I'm maintaining this library)