看啥推荐读物
专栏名称: Python小屋
清华出版社《Python程序设计》系列教材作者董付国的Python小屋。介绍Python基础语法知识、标准库、扩展库知识,探讨Python在各领域的应用。
今天看啥  ›  专栏  ›  Python小屋

Python批量导入图片生成PowerPoint 2007+文件

Python小屋  · 公众号  · Python  · 2017-11-09 20:41
说明:本文是“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), ………………………………

原文地址:访问原文地址
快照地址: 访问文章快照