網站首頁 編程語言 正文
一、原理
如題,我有一個模板課件.pptx:
其內容:
我想復制模板中間的某一頁多次,比如復制第1頁,然后復制3次,
prs = Presentation(r"D:\自動化\課件.pptx") for i in range(0,3): copied_slide = duplicate_slide(prs, 0)
次數是根據我的需求指定的,使用python pptx
模塊復制,
def duplicate_slide(pres,index): template = pres.slides[index] blank_slide_layout = pres.slide_layouts[index] copied_slide = pres.slides.add_slide(blank_slide_layout) for shp in template.shapes: el = shp.element newel = copy.deepcopy(el) copied_slide.shapes._spTree.insert_element_before(newel, 'p:extLst') for _, value in six.iteritems(template.part.rels): # Make sure we don't copy a notesSlide relation as that won't exist if "notesSlide" not in value.reltype: copied_slide.part.rels.add_relationship(value.reltype, value._target, value.rId) return copied_slide
然后保存成另一個pptx文件
path = r'D:\自動化\result.pptx' prs.save(path)
復制后的ppt內容
二、所有代碼
import copy,six from pptx import Presentation def duplicate_slide(pres,index): template = pres.slides[index] blank_slide_layout = pres.slide_layouts[index] copied_slide = pres.slides.add_slide(blank_slide_layout) for shp in template.shapes: el = shp.element newel = copy.deepcopy(el) copied_slide.shapes._spTree.insert_element_before(newel, 'p:extLst') for _, value in six.iteritems(template.part.rels): # Make sure we don't copy a notesSlide relation as that won't exist if "notesSlide" not in value.reltype: copied_slide.part.rels.add_relationship(value.reltype, value._target, value.rId) return copied_slide prs = Presentation(r"D:\自動化\課件.pptx") for i in range(0,3): copied_slide = duplicate_slide(prs, 0) path = r'D:\自動化\result.pptx' prs.save(path)
原文鏈接:https://blog.csdn.net/biggbang/article/details/128839633
相關推薦
- 2022-12-21 Redis?RDB與AOF持久化方式詳細講解_Redis
- 2023-03-16 Android藍牙服務啟動流程分析探索_Android
- 2022-05-17 qt 錯誤GL/gl.h: No such file or directory的解決方法
- 2022-12-03 React前端解鏈表數據結構示例詳解_React
- 2022-09-03 python通過ElementTree操作XML_python
- 2022-04-20 Flutter如何輕松實現動態更新ListView淺析_Android
- 2022-04-04 Python數據處理-導入導出excel數據_python
- 2022-07-07 Asp.Net上傳文件并配置可上傳大文件的方法_基礎應用
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支