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

Python利用pptx操作PPT實(shí)現(xiàn)幻燈片的刪除與替換

 更新時(shí)間:2023年02月03日 08:51:12   作者:虛壞叔叔  
這篇文章主要為大家詳細(xì)介紹了python如何使用pptx庫實(shí)現(xiàn)操作PPTx幻燈片文件刪除并替換圖片,文中的示例代碼講解詳細(xì),感興趣的可以嘗試一下

一、原理

通過查找ppt中的圖片指紋替換

二、操作流程

原始ppt如下:

根據(jù)oldpic.png的md5指紋 找到圖片

if md5img == md5finger:                   
                    slide.shapes.add_picture(newpic, shape.left, shape.top, shape.width, shape.height)
                    e.getparent().remove(e)

oldpic.png

想要替換的newpic.png

最后生成的成果如下:

三、代碼

完整代碼如下:

def replace_pic4shapes(filename, newpic, oldpic):
    # 把舊樣本圖片Logo,獲取指紋
    imageFile = open(oldpic, "rb")
    imgBlob = imageFile.read()
    md5finger = hashlib.md5(imgBlob).hexdigest()
    prs = Presentation(filename)
 
    for slide in list(prs.slides)[0:]:
        for shape in list(slide.shapes):
            ispicture= False
            try:
                md5img = hashlib.md5(shape.image.blob).hexdigest()
                ispicture = True
            except:
                pass
            e = shape.element
            if ispicture:
                if md5img == md5finger:                   
                    slide.shapes.add_picture(newpic, shape.left, shape.top, shape.width, shape.height)
                    e.getparent().remove(e)
                pass
 
    prs.save("課件工坊-長征組歌新文件.pptx")

到此這篇關(guān)于Python利用pptx操作PPT實(shí)現(xiàn)幻燈片的刪除與替換的文章就介紹到這了,更多相關(guān)Python PPT幻燈片刪除替換內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

峨边| 西和县| 右玉县| 醴陵市| 洛川县| 胶南市| 新丰县| 沂源县| 东至县| 聊城市| 揭东县| 冀州市| 屏东县| 玉溪市| 余干县| 登封市| 兴宁市| 嘉祥县| 高碑店市| 张家口市| 沭阳县| 循化| 保康县| 龙川县| 乌拉特前旗| 丹阳市| 东乡族自治县| 林口县| 西丰县| 大方县| 新郑市| 温泉县| 南投县| 宁阳县| 普格县| 浦城县| 阳泉市| 龙川县| 惠水县| 尤溪县| 芒康县|