说明:本文是“Python批量爬取微信公众号文章中的图片”的后续文章,用来把从公众号批量抓取的图片还原为PowerPoint 2007文件。使用方法:安装扩展库python-pptx,然后把上文中抓取的图片和本程序放在同一个文件夹。import osimport pptxfrom pptx.util import InchespptFile = pptx.Presentation()picFiles = [fn for fn in os.listdir() if fn.endswith('.png')]# 按图片编号顺序导入for fn in sorted(picFiles, key=lambda item:int(item[:item.rindex('.')])): slide = pptFile.slides.add_slide(pptFile.slide_layouts[1]) # 为PPTX文件当前幻灯片中第一个文本框设置文字,本文代码中可忽略 slide.shapes.placeholders[0].text = fn[:fn.rindex('.')] # 导入并为当前幻灯片添加图片,起始位置和尺寸可修改 slide.shapes.add_picture(fn, Inches(0), Inches(0),
………………………………