VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > python入门教程 >
  • python操作pptx设置title字体大小插入全屏图片A4尺寸实例一枚

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') # 保存为文件


出处:https://www.cnblogs.com/prefertea/p/17337052.html


相关教程