Skip to content

Exporting to PowerPoint

Matthew Cowley edited this page Jan 20, 2022 · 1 revision

It sometimes useful to directly export from python to PowerPoint if you multiple graphs to export which may change. To do this you can use the pptx package which can be installed using "pip install python-pptx". Below is a basic example of how to use it:

#do some standard imports
from pptx import Presentation
from pptx.util import Inches,Cm

prs = Presentation(filepath+'Selco_Appen.pptx') #load powerpoint

slide = prs.slides[slide_number] #open slide indexed by 0 

###### add image to slide ######
left = Inches(0.1) #define distance can use cm or inches or whatever
top = Inches(1.03)
pic = slide.shapes.add_picture(img_path, left, top, width=Cm(12), height=Cm(7)) #adds picture 

#open another slide
slide = prs.slides[slide_number+2]

###### add text to slide ######
txBox = slide.shapes.add_textbox( width=Inches(5), height=Inches(4),left=Inches(2), top=Inches(3.80))
tf = txBox.text_frame
tf.text = "Some text to insert into my powerpoint" #add text to text box

#save the changes that have been made
prs.save(filepath+'Selco_Appen.pptx')

stuff

Clone this wiki locally