[英]How to add text in superscript or subscript with python docx
在python docx快速入門指南( https://python-docx.readthedocs.io/en/latest/ )中,您可以看到可以使用add_run-command並在句子中添加粗體文本。
document = Document()
document.add_heading('Document Title', 0)
p = document.add_paragraph('A plain paragraph having some ')
p.add_run('bold').bold = True
我會使用相同的add_run-command,而是添加上標或下標的文本。
這有可能實現嗎?
任何幫助非常感謝!
/ V
對add_run()
的調用返回一個可用於更改字體選項的Run
對象。
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')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.