Python使用pptx實(shí)現(xiàn)復(fù)制頁面到其他PPT中
一、原理
如題,我有一個(gè)模板課件.pptx:

其內(nèi)容:

我想復(fù)制模板中間的某一頁多次,比如復(fù)制第1頁,然后復(fù)制3次,
prs = Presentation(r"D:\自動(dòng)化\課件.pptx")
for i in range(0,3):
copied_slide = duplicate_slide(prs, 0)
次數(shù)是根據(jù)我的需求指定的,使用python pptx模塊復(fù)制,
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
然后保存成另一個(gè)pptx文件
path = r'D:\自動(dòng)化\result.pptx' prs.save(path)

復(fù)制后的ppt內(nèi)容

二、所有代碼
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:\自動(dòng)化\課件.pptx")
for i in range(0,3):
copied_slide = duplicate_slide(prs, 0)
path = r'D:\自動(dòng)化\result.pptx'
prs.save(path)
到此這篇關(guān)于Python使用pptx實(shí)現(xiàn)復(fù)制頁面到其他PPT中的文章就介紹到這了,更多相關(guān)Python pptx復(fù)制PPT頁面內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python把csv數(shù)據(jù)寫入list和字典類型的變量腳本方法
今天小編就為大家分享一篇Python把csv數(shù)據(jù)寫入list和字典類型的變量腳本方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-06-06
python實(shí)現(xiàn)從ftp上下載文件的實(shí)例方法
在本篇文章里小編給大家整理了關(guān)于python實(shí)現(xiàn)從ftp上下載文件的實(shí)例方法,需要的朋友們可以參考下。2020-07-07
Python數(shù)據(jù)分析之雙色球統(tǒng)計(jì)單個(gè)紅和藍(lán)球哪個(gè)比例高的方法
這篇文章主要介紹了Python數(shù)據(jù)分析之雙色球統(tǒng)計(jì)單個(gè)紅和藍(lán)球哪個(gè)比例高的方法,涉及Python數(shù)值運(yùn)算及圖形繪制相關(guān)操作技巧,需要的朋友可以參考下2018-02-02
Pandas中數(shù)據(jù)表合并的幾種實(shí)現(xiàn)方法
Pandas提供了merge()、concat()和join()三種方法來合并數(shù)據(jù)表,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-12-12
keras的三種模型實(shí)現(xiàn)與區(qū)別說明
這篇文章主要介紹了keras的三種模型實(shí)現(xiàn)與區(qū)別說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07
Python實(shí)現(xiàn)將MySQL數(shù)據(jù)庫表中的數(shù)據(jù)導(dǎo)出生成csv格式文件的方法
這篇文章主要介紹了Python實(shí)現(xiàn)將MySQL數(shù)據(jù)庫表中的數(shù)據(jù)導(dǎo)出生成csv格式文件的方法,涉及Python針對(duì)mysql數(shù)據(jù)庫的連接、查詢、csv格式數(shù)據(jù)文件的生成等相關(guān)操作技巧,需要的朋友可以參考下2018-01-01
Python SqlAlchemy動(dòng)態(tài)添加數(shù)據(jù)表字段實(shí)例解析
這篇文章主要介紹了Python SqlAlchemy動(dòng)態(tài)添加數(shù)據(jù)表字段實(shí)例解析,分享了相關(guān)代碼示例,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-02-02
Django2.2配置xadmin的實(shí)現(xiàn)
這篇文章主要介紹了Django2.2配置xadmin的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05

