python - 使用现有的 pptx Python-Pptx 创建新的 pptx
问题描述
我正在尝试使用 old.pptx 创建 new.pptx 。old.pptx 中有 4 张幻灯片。我想在 4 张幻灯片中创建具有几乎相同内容且文本修改很少的 new.pptx。我从下面的代码中跳过了修改部分,你可以举一个例子,比如将小写字母转换为大写字母。需要在运行时做这些事情,这样如果我只是通过 old.pptx 它将执行所需的操作和然后将其写入具有相同编号的新 pptx。幻灯片..我不知道如何在下面进行调整,可能需要完全改变它。请看下面的代码..
from pptx import Presentation
prs1 = Presentation()
prs = Presentation('old.pptx')
title_slide_layout = prs1.slide_layouts[0]
for slide in prs.slides:
for shape in slide.shapes:
if not shape.has_text_frame:
continue
for paragraph in shape.text_frame.paragraphs:
#print(paragraph.text)
prs1.slides.add_slide(paragraph.text)
prs1.save('new.pptx')
解决方案
您只需打开演示文稿,进行所需的更改,然后用新名称保存它,即可创建演示文稿的“修改”副本。
from pptx import Presentation
prs = Presentation('original.pptx')
for slide in prs.slides:
for shape in slide.shapes:
if not shape.has_text_frame:
continue
text_frame = shape.text_frame
text_frame.text = translate(text_frame.text)
prs.save('new.pptx')
如果您为此提供translate(text) -> translated text
功能,它将执行您的要求。
推荐阅读
- powershell - 检测 Windows 系统区域设置是否使用 UTF-8 代码页的脚本?
- out-of-memory - 什么是 ActiveMQ.Advisory.Consumer.Queue Enqueue #。为什么一直在增加
- numpy - 使用 NumPy 的逐元素矩阵向量乘积
- python - Python Dataframe 从数百万行的大日期时间索引中提取唯一日期列表
- c# - 是否可以在不使用 ToList() 的情况下使用派生类集合中的基类/接口集合
- swift - 具有恒定高度和动态宽度的 UICollectionView 单元格取决于 UIImageView 宽度
- python - Python没有遍历列表中的项目
- python - 有没有办法迭代一个模式以在 Python 中使用 matplotlib 顺时针重复它?
- amazon-web-services - AWS Kinesis Data Analytics:分析流数据可以回答什么问题?
- nginx - *44 connect() 在连接上游 jhipster 时失败(111:连接被拒绝)