最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python使用pptx實(shí)現(xiàn)復(fù)制頁面到其他PPT中

 更新時(shí)間:2023年02月02日 10:19:13   作者:虛壞叔叔  
這篇文章主要為大家詳細(xì)介紹了python如何使用pptx庫實(shí)現(xiàn)從一個(gè)ppt復(fù)制頁面到另一個(gè)ppt里面,文中的示例代碼講解詳細(xì),感興趣的可以嘗試一下

一、原理

如題,我有一個(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)文章

最新評(píng)論

伊宁县| 金乡县| 寿阳县| 汾阳市| 天峻县| 清丰县| 莫力| 莒南县| 彩票| 丘北县| 都安| 黄山市| 咸宁市| 边坝县| 保定市| 敖汉旗| 九龙县| 江北区| 常山县| 西充县| 钟山县| 韩城市| 营山县| 淳安县| 土默特右旗| 高青县| 托里县| 清河县| 府谷县| 噶尔县| 乐至县| 怀化市| 斗六市| 阿瓦提县| 厦门市| 南皮县| 乳源| 盐城市| 临漳县| 昌图县| 呼图壁县|