长虫山小木屋

没有谁会为你踏雪而来 喜欢的风景要躬亲筚路

  博客园  :: 首页  :: 新随笔  :: 联系 ::  :: 管理
  115 随笔 :: 0 文章 :: 6 评论 :: 90332 阅读
1
pip install python-pptx

安装好pptx,设置标题最大的作用是ppt里面的摘要视图显示摘要文字

参考:https://python-pptx.readthedocs.io/en/latest/

 

复制代码
from pptx import Presentation
from pptx.util import Cm

pwidth,pheight=Cm(29.7),Cm(21)#A4大小297*210
left=top=0
prs = Presentation() # 实例化一个ppt演示文稿对象
prs.slide_width=pwidth
prs.slide_height=pheight
title_only_slide_layout  = prs.slide_layouts[5] #实例化模板
slide = prs.slides.add_slide(title_only_slide_layout) # 向文件中添加带标题的页面
slide.shapes.title.text="四大皆空副驾驶的1四大皆空副驾驶的1四大皆空副驾驶的1四大皆空副驾驶的1四大皆空副驾驶的1四大皆空副驾驶的1四大皆空副驾驶的1"
slide.shapes.title.left=left
slide.shapes.title.top=top
slide.shapes.title.width=pwidth
slide.shapes.title.height=pheight
title_para = slide.shapes.title.text_frame.paragraphs[0]
title_para.font.name = "微软雅黑"
title_para.font.size = Cm(1)

img_path = './helloworld.jpg' # 图片路径
# 在页面中插入图片
pic = slide.shapes.add_picture(img_path,left,top,pwidth,pheight)

slide = prs.slides.add_slide(title_only_slide_layout) # 再来一个页面,对比下
slide.shapes.title.text="四大皆空副驾驶的2"
title_para = slide.shapes.title.text_frame.paragraphs[0]
title_para.font.name = "楷体"
title_para.font.size = Cm(2)

prs.save('自动生成的ppt.pptx') # 保存为文件
复制代码

 

posted on   长虫山小木屋  阅读(171)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示