I have been trying to create the "two-content" slides layout where there is a title and some content to the left and right of vertically split section
My code is as follows:
import collections
import collections.abc
from pptx import Presentation
presentation = Presentation()
slide_layout = presentation.slide_layouts[5]
slide = presentation.slides.add_slide(slide_layout)
content1 = slide.placeholders[1]
content1.text = 'First content'
content2 = slide.placeholders[2]
content2.text = 'Second content'
presentation.save('presentation.pptx')
print("Presentation created successfully.")
I keep getting the following error PS C:\Users\dell\Desktop\Slide Generator\SlidesGenerator> & C:/Users/dell/AppData/Local/Programs/Python/Python311/python.exe "c:/Users/dell/Desktop/Slide Generator/SlidesGenerator/twocontent.py" Traceback (most recent call last): File "c:\Users\dell\Desktop\Slide Generator\SlidesGenerator\twocontent.py", line 8, in content1 = slide.placeholders[1] ~~~~~~~~~~~~~~~~~~^^^ File "C:\Users\dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\shapes\shapetree.py", line 766, in getitem raise KeyError("no placeholder on this slide with idx == %d" % idx) KeyError: 'no placeholder on this slide with idx == 1'
You need slide layout 3
import collections
import collections.abc
from pptx import Presentation
presentation = Presentation()
slide_layout = presentation.slide_layouts[3]
slide = presentation.slides.add_slide(slide_layout)
content1 = slide.placeholders[1]
content1.text = 'First content'
content2 = slide.placeholders[2]
content2.text = 'Second content'
presentation.save('presentation.pptx')
print("Presentation created successfully.")