I am trying to automate report generating in PowerPoint by python. I wanted to know if there is any way to detect an existing textbox from a PowerPoint template and then fill it with some text in python?
Main logic is that how to find a placeholder
which is given by template by default as well as text-box
on non-template-pages
. We can take different type
to extract data and fill placeholder and text-box
like From txt file, form web scraping and many more. Among them we have taken our data list_
object.
1. Lets we n
page and we are accessing page 1
so we can access this page usng this code :
(pptx.Presentation(inout_pptx)).slides[0]
2. To select placeholder
by default provided in template we will use this code and we will iterator over all placehodler
slide.shapes
3. To update particular placeholder
use this :
shape.text_frame.text = data
CODE :
import pptx
inout_pptx = r"C:\\Users\\lenovo\\Desktop\\StackOverFlow\\python_pptx.pptx"
list_data = [
'Quantam Computing dsfsf ',
'Welcome to Quantam Computing Tutorial, hope you will get new thing',
'User_Name sd',
'<Enrollment Number>']
"""open file"""
prs = pptx.Presentation(inout_pptx)
"""get to the required slide"""
slide = prs.slides[0]
"""Find required text box"""
for shape, data in zip(slide.shapes, list_data):
if not shape.has_text_frame:
continue
shape.text_frame.text = data
"""save the file"""
prs.save(inout_pptx)
RESULTS :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With