如果不改变所有文本的整个字体大小,我就无法将字体大小从一种大小更改为另一种大小。
这是因为您正在更改
style
物体:
Tstyle = doc.styles['Normal']
font = Tstyle.font # << this line assigns font = doc.styles['Normal'].font
因此,您没有使用一些通用的“字体”属性,而是使用属于命名样式“普通”的字体。所以:
font.name = "Nunito Sans"
font.size = Pt(48) # << this line changes the font size of doc.styles['Normal']
未测试,但尝试以下操作:
TStyle, FStyle = doc.styles['Normal'], doc.styles['Heading 1']
for style in (TStyle, FStyle):
style.font.name = "Nunito Sans"
TStyle.font.size = Pt(48)
FStyle.font.size = Pt(24)
Title = doc.add_paragraph()
Title.style = TStyle
TRun = Title.add_run("Finance Log")
TRun.bold = True
FCreated = Title.add_run("\nFile Created On {0}".format(datetime.datetime.now().strftime('%d-%m-%y')))
FLog = doc.add_paragraph()
FLog.style = FStyle
FinanceTitle = FLog.add_run("Log Begins:")
doc.save(path_to_docx)