ReK*_*eKx 3 python docx python-3.x python-docx
我们如何将字体名称、大小等应用于 python docx 中的 add_run()。
我已经尝试了以下但它不起作用。
run = Document().add_paragraph().add_run()
font = run.font
font.name = “MS Gothic”
Document().add_paragraph().add_run(“Some random text”)
Run Code Online (Sandbox Code Playgroud)
小智 5
对于每个句子,请尝试以下操作:
import docx
document = docx.Document()
run = document.add_paragraph().add_run()
'''Apply style'''
style = document.styles['Normal']
font = style.font
font.name = 'MS Gothic'
font.size = docx.shared.Pt(15)
paragraph = document.add_paragraph('Some text\n')
'''Add another sentence to the paragraph'''
sentence = paragraph.add_run('A new line that should have a different font')
'''Then format the sentence'''
sentence.font.name = 'Arial'
sentence.font.size = docx.shared.Pt(10)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6973 次 |
| 最近记录: |