python-docx 设置标题heading的中文字体类型+设置正文的中文字体类型

依赖包:

from docx import Document
from docx.shared import Pt
from docx.shared import Inches
from docx.oxml.ns import qn

修改正文的中文字体类型,示例代码:(全局设置)

    document=Document()
    document.styles['Normal'].font.name=u'微软雅黑'
    document.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')

修改3级标题的字体类型,示例代码:

            run = document.add_heading('',level=3).add_run(u"应用场景示例: ")#应用场景示例标题
            run.font.name=u'微软雅黑'
            run._element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑') 

猜你喜欢

转载自www.cnblogs.com/apple2016/p/9635061.html
今日推荐