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

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

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

一、原理

通過(guò)查找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("課件工坊-長(zhǎng)征組歌新文件.pptx")

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

相關(guān)文章

最新評(píng)論

准格尔旗| 抚松县| 武夷山市| 连平县| 南城县| 营山县| 锡林郭勒盟| 邹平县| 宜州市| 山西省| 天祝| 肥西县| 锦屏县| 孙吴县| 定兴县| 贺州市| 木兰县| 诏安县| 察哈| 沙河市| 靖安县| 河北区| 靖江市| 新蔡县| 昭觉县| 乌兰浩特市| 盖州市| 讷河市| 陕西省| 沂源县| 韶山市| 丹阳市| 勐海县| 乾安县| 桃江县| 屏南县| 博白县| 湄潭县| 招远市| 民权县| 武穴市|