首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Python批量导入图片生成PowerPoint 2007+文件

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

作者头像
Python小屋屋主
发布于 2018-04-16 16:05:50
发布于 2018-04-16 16:05:50
2.6K0
举报
文章被收录于专栏:Python小屋Python小屋

使用方法:安装扩展库python-pptx,然后把上文中抓取的图片和本程序放在同一个文件夹。

import os import pptx from pptx.util import Inches

pptFile = 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), Inches(10), Inches(7.5)) pptFile.save('第三章.pptx')

附:代码截图

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2017-11-09,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档