from docx import Document
from docx.shared import Pt
document = Document()
first_paragraph = document.add_paragraph()
first_style = first_paragraph.add_run('我是中国人') #新增首行样式并添加文字
first_style.font.size = Pt(20) # 设置字号样式
first_style.font.name = '黑体' # 设置字体样式
document.save('我是中国人.docx')
结果'黑体'样式没能显示出来,只有默认的什么'MS Mincho',请问这是什么原因呢?
测试了一下,你的代码仅能对英文字符生效
可行的方式是修改样式,通过不同的样式控制中文字体
参考网站
https://cloud.tencent.com/dev...