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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python實(shí)現(xiàn)讀取命令行參數(shù)的方法
這篇文章主要介紹了python實(shí)現(xiàn)讀取命令行參數(shù)的方法,涉及Python中sys模塊的相關(guān)使用技巧,需要的朋友可以參考下2015-05-05Python 20行簡(jiǎn)單實(shí)現(xiàn)有道在線翻譯的詳解
這篇文章主要介紹了Python實(shí)現(xiàn)有道在線翻譯的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05Python利用Selenium實(shí)現(xiàn)彈出框的處理
經(jīng)常出現(xiàn)在網(wǎng)頁上的基于JavaScript實(shí)現(xiàn)的彈出框有三種,分別是?alert、confirm、prompt?。本文主要是學(xué)習(xí)如何利用selenium處理這三種彈出框,感興趣的可以了解一下2022-06-06解決Jupyter Notebook使用parser.parse_args出現(xiàn)錯(cuò)誤問題
這篇文章主要介紹了解決Jupyter Notebook使用parser.parse_args出現(xiàn)錯(cuò)誤問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-04-04python 在右鍵菜單中加入復(fù)制目標(biāo)文件的有效存放路徑(單斜杠或者雙反斜杠)
這篇文章主要介紹了python 在右鍵菜單中加入復(fù)制目標(biāo)文件的有效存放路徑(單斜杠或者雙反斜杠),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04Python流程控制 while循環(huán)實(shí)現(xiàn)解析
這篇文章主要介紹了Python流程控制 while循環(huán)實(shí)現(xiàn)解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09