我试图在单词文档中写两个句子,每个句子使用不同的字体,但是当我运行此代码时:
import docx
import os
from docx.shared import Inches
from docx.shared import Pt
normfont = doc.styles['Normal']
font = normfont.font
font.name = 'Arial'
font.size = Pt(25)
arialparagraph= doc.add_paragraph()
arialparagraph.style = doc.styles['Normal']
arialparagraph.add_run("This line is using one font")
lcd = doc.styles['Normal']
font = lcd.font
font.name = 'Modern LCD-7'
font.size = Pt(30)
lcdparagraph = doc.add_paragraph()
lcdparagraph.style = doc.styles['Normal']
lcdparagraph.add_run("This line is using a different font")
整个文档仅使用最后定义的字体(现代LCD-7)。
这是因为我要覆盖常规样式。有没有办法建立自己的风格?例如doc.style['LCD']
?