python - 使用带有现有模板的 powerpoint 文件
问题描述
我正在使用 python-pptx 生成一个 powerpoint 文件。如何使文件维护文件上的现有模板而不覆盖文件上的模板。
解决方案
打开文件,保存到新路径,然后从新路径重新打开:
def create_new_presentation(templateFileName, outputFileName):
"""
creates a new PPTX file from the template path -- this will OVERWRITE outputFileName if exists.
templateFileName: path to 'template' file
outputFileName: path to the output file
"""
p = Presentation(templateFileName)
p.save(outputFileName)
p = Presentation(outputFileName)
return p
或者,您可以这样做shutil.copyfile
:
from shutil import copyfile
def create_new_presentation(templateFileName, outputFileName):
"""
creates a new PPTX file from the template path -- this will OVERWRITE outputFileName if exists.
templateFileName: path to 'template' file
outputFileName: path to the output file
"""
copyfile(templateFileName, outputFileName)
return Presentation(outputFileName)
推荐阅读
- java - 使用JNA获取特定进程的dll基地址
- java - 具有父复合 pk 的 JPA OneToMany 是子主键派生实体问题的一部分
- c# - 如何将我从 CMD 获得的结果拆分为变量?
- optimization - 我可以删除带有 at 符号的注释以进行代码优化吗?
- powershell - 用于列出 sftp 服务器文件夹中的文件的 PowerShell 脚本
- ios - 带有 --profile 标志的 Flutter iOS 命令行构建失败,但发布模式有效(都在真实设备上)
- flutter - 无法上传从 Flutter 上的图库中选择的图像:“无法从 blob 中提取文件路径”
- python - 如何修复 Airflow dag 中的失败任务
- android - APK 运行脚本 Android Zebra 版本 10 更改 JSON 文件中的一行并保存
- ios - Mac M1 上的 Flutter 2.5 - 未找到架构 arm64 的符号