依赖包:
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'微软雅黑')