如何使用python docx在上标或下标中添加文本 [英] How to add text in superscript or subscript with python docx
本文介绍了如何使用python docx在上标或下标中添加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在python docx快速入门指南中(
In the python docx quickstart guide (https://python-docx.readthedocs.io/en/latest/) you can see that it is possible to use the add_run-command and add bold text to a sentence.
document = Document()
document.add_heading('Document Title', 0)
p = document.add_paragraph('A plain paragraph having some ')
p.add_run('bold').bold = True
I would to use the same add_run-command but instead add text that is superscripted or subscripted.
Is this possible to achieve?
Any help much appreciated!
/V
解决方案
The call to add_run()
returns a Run
object that you can use to change font options.
from docx import Document
document = Document()
p = document.add_paragraph('Normal text with ')
super_text = p.add_run('superscript text')
super_text.font.superscript = True
p.add_run(' and ')
sub_text = p.add_run('subscript text')
sub_text.font.subscript = True
document.save('test.docx')
这篇关于如何使用python docx在上标或下标中添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文