I am writing a python script to create a ppt file of images and text.
Each slide will contain a heading, subheading and below of it will contain the image as shown in picture below.
I run code but it is giving me error -
AttributeError: 'SlidePlaceholder' object has no attribute 'insert_picture'
Code is -
from pptx import Presentation
import os
prs = Presentation()
class MySlide:
def __init__(self, data):
self.layout = prs.slide_layouts[data[3]]
self.slide=prs.slides.add_slide(self.layout)
self.title=self.slide.shapes.title
self.title.text=data[0]
self.subtitle=self.slide.placeholders[1]
self.subtitle.text=data[1]
if data[2] != "":
self.slide.placeholders[2].insert_picture(data[2])
slides = [
["Sample Title 1", #data[0]
"Sample Subtitle 1",
"image1.jpg",
3],
["Sample Title 2", #data[0]
"Sample Subtitle 2",
"image2.jpg",
3],
["Sample Title 3", #data[0]
"Sample Subtitle 3",
"image3.jpg",
3]
]
for each_slide in slides:
MySlide(each_slide)
prs.save("stack.pptx")
os.startfile("stack.pptx")
Currently, code has 3 slides.
