Set paragraph font in python-docx

后端 未结 4 1559
遇见更好的自我
遇见更好的自我 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条回答
  •  -上瘾入骨i
    2020-12-16 22:10

    The documentation for python-docx is here: http://python-docx.readthedocs.org/en/latest/

    The styles that are available in the default template are listed here: http://python-docx.readthedocs.org/en/latest/user/styles.html

    In your example above you used a typeface name ("Times New Roman") instead of a style id. If you use "Heading1" for example, that would change the look of the font, among other things, since it's a paragraph style.

    At present there is no API for directly applying a typeface name or font size to text in python-docx, although that and more is coming in the next release, probably within a month. In the meantime, you can define styles for the paragraph and character settings you want and apply those styles. Using styles is the recommended way to apply formatting in Word, similar to how CSS is the recommended way to apply formatting to HTML.

提交回复
热议问题