因此,我正在尝试解决Python Docx的问题。我需要重构我的.docx文档,我需要更改所有文档的字体名称和字体大小。您能提出什么解决方案?
使用此代码,“字体名称”正在更改,但“字体大小”没有更改。
from docx import Document
from docx.shared import Pt
document = Document('path/to/file.docx')
style = document.styles['Normal']
font = style.font
font.name = 'Arial'
font.size = Pt(10)
for paragraph in document.paragraphs:
paragraph.style = document.styles['Normal']
document.save('refactored.docx')
答案 0 :(得分:0)
您需要遍历运行。
for paragraph in document.paragraphs:
paragraph.style = document.styles['Normal']
for run in paragraph.runs:
run.font.size = Pt(10)