python_修改PPT中字体,run.font.name只对英文生效怎么办?
from pptx import Presentation
from pptx.util import Pt
from pptx_ea_font import set_font
# 打开现有的 PPT 文件
prs = Presentation('D:\\desktop\\测试论文\\PPT模板_正文.pptx')
# 遍历每一张幻灯片
for slide in prs.slides:
# 遍历每个形状
for shape in slide.shapes:
if shape.has_text_frame:
text_frame = shape.text_frame
# 遍历每个段落
for paragraph in text_frame.paragraphs:
# 遍历每个运行(run)
for run in paragraph.runs:
# 输出调试信息
print(f"Original text: {run.text}, Original font: {run.font.name}")
# 设置英文字体或数字
run.font.name = '华文行楷'
# 设置中文字体
set_font(run, '华文行楷')
run.font.size = Pt(12) # 设置字体大小
run.font.bold = False # 设置加粗
run.font.italic = False # 设置斜体
run.font.underline = False # 设置下划线
# 输出调试信息
print(f"Modified text: {run.text}, Modified font: {run.font.name}")
# 保存修改后的 PPT 文件
prs.save('D:\\desktop\\测试论文\\你好.pptx')