2016-11-22 304 views
1

python docxクイックスタートガイド(https://python-docx.readthedocs.io/en/latest/)では、add_runコマンドを使用して、太字のテキストを文に追加することができます。上付き文字または下付き文字をpythonで追加する方法docx

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コマンドを使用しますが、代わりに上付き文字または下付き文字を追加します。

これは実現可能ですか?

ご迷惑をおかけして申し訳ありません。

/V

答えて

2

add_run()への呼び出しは、あなたがfont optionsを変更するために使用することができます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') 

enter image description here

+0

高速な答えをありがとう!そしてそれは働いている! – viktortl

関連する問題