Python 官方文档:入门教程 => 点击学习
目录一、原理二、操作流程三、代码一、原理 通过查找ppt中的图片指纹替换 二、操作流程 原始ppt如下: 根据oldpic.png的md5指纹 找到图片 if md5img ==
通过查找ppt中的图片指纹替换
原始ppt如下:
根据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")
到此这篇关于python利用pptx操作PPT实现幻灯片的删除与替换的文章就介绍到这了,更多相关Python PPT幻灯片删除替换内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: Python利用pptx操作PPT实现幻灯片的删除与替换
本文链接: https://www.lsjlt.com/news/194065.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0