Generate PowerPoint with Python
You
can I generate a basic powerpoint slideshow using python code?
ChatGPT
Yes! You can generate a basic PowerPoint slideshow using Python with the python-pptx
library. It allows you to create and modify .pptx
files programmatically.
Installation
If you haven’t installed python-pptx
, you can do so using:
pip install python-pptx
Example Code: Creating a Basic PowerPoint Presentation
This script generates a simple PowerPoint file with a title slide and a content slide.
from pptx import Presentation
# Create a new presentation
prs = Presentation()
# Add a title slide
slide_layout = prs.slide_layouts[0] # Title Slide Layout
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "My Presentation"
subtitle.text = "Created with Python"
# Add a content slide
slide_layout = prs.slide_layouts[1] # Title and Content Layout
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
content = slide.placeholders[1]
title.text = "Second Slide"
content.text = "This is some content text."
# Save the presentation
prs.save("generated_presentation.pptx")
print("Presentation created successfully!")
Features You Can Add
- Images:
- Tables:
- Custom Formatting:
Would you like to customize it further, like adding charts or animations?