首页 > 编程语言 > 详细

py python-pptx 创建ppt

时间:2020-11-20 19:13:54      阅读:37      评论:0      收藏:0      [点我收藏+]
from pptx import Presentation

class Main():
  def __init__(self):
    prs = Presentation()
    title_slide_layout = prs.slide_layouts[0]

    slide = prs.slides.add_slide(title_slide_layout)
    title = slide.shapes.title
    subtitle = slide.placeholders[1]

    slide1 = prs.slides.add_slide(title_slide_layout)
    title1 = slide1.shapes.title
    subtitle1 = slide1.placeholders[1]

    title.text = "Hello, World!"
    subtitle.text = "python-pptx was here!"

    title1.text = "Hello, World! 1"
    subtitle1.text = "python-pptx was here! 1"

    prs.save(‘./test.pptx‘)

Main()

使用模板

from pptx import Presentation
from pptx.dml.color import RGBColor

class Main():
  def __init__(self):
    prs = Presentation(‘./temp.pptx‘)

    prs.slides[0].shapes.title.text = ‘new title‘
    prs.slides[0].placeholders[1].text = ‘new subtitle‘

    prs.slides[1].shapes.title.text = ‘new title 1‘
    prs.slides[1].shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255,255, 255) # 设置文本颜色
    prs.slides[1].placeholders[1].text = ‘new subtitle 1‘
    prs.slides[1].placeholders[1].text_frame.paragraphs[0].font.color.rgb = RGBColor(255,255, 255)
   

    prs.save(‘./test.pptx‘)

Main()

py python-pptx 创建ppt

原文:https://www.cnblogs.com/ajanuw/p/14012403.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!