Set paragraph font in python-docx

后端 未结 4 1562
遇见更好的自我
遇见更好的自我 2020-12-16 21:27

I am using python-docx 0.7.6.

I can\'t seem to be able to figure out how to set font family and size for a certain paragraph.

There is .style pr

4条回答
  •  死守一世寂寞
    2020-12-16 21:52

    This is how to set the Normal style to font Arial and size 10pt.

    from docx.shared import Pt
    
    style = document.styles['Normal']
    font = style.font
    font.name = 'Arial'
    font.size = Pt(10)
    

    And this is how to apply it to a paragraph.

    paragraph.style = document.styles['Normal']
    

    Using the current version of python-docx (0.8.5).

提交回复
热议问题