【python_修改PPT中字体,run.font.name只对英文生效怎么办?】

python_修改PPT中字体,run.font.name只对英文生效怎么办?

参考:使用pptx_ea_font库设置中文字体

复制代码
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')
相关推荐
RSABLOCKCHAIN3 小时前
AI Agents in LangGraph-2
人工智能·python
WA内核拾荒者3 小时前
WhatsApp 账号异常检测的自动化告警系统设计
数据库·python·自动化
码流怪侠4 小时前
【GitHub】Bend:让 GPU 并行编程像写 Python 一样简单
python·github
魔力女仆4 小时前
分享一个 JS 鼠标跟随贪吃蛇背景库
开发语言·javascript·计算机外设
2401_894915535 小时前
GEO 搜索优化完整源码从零部署:环境配置、集群搭建全流程
开发语言·python·tcp/ip·算法·unity
麻瓜老宋6 小时前
AI开发C语言应用按步走,表达式计算器calc的第二十二步,分号赋值链式修复、TOKEN_ASSIGN
c语言·开发语言·atomcode
zhiSiBuYu05177 小时前
Python3 模块开发与应用实战指南
python
颜x小8 小时前
[C#] C++与c#语法对比
开发语言·c++·c#
databook8 小时前
用方差阈值过滤掉“惰性特征”
python·机器学习·scikit-learn