【发布时间】:2019-08-18 22:00:21
【问题描述】:
所以,我试图用 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')
【问题讨论】:
标签: python xml python-3.x ms-word python-docx