Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I embed a python plot chart (or image) in ppt and refresh it

I can open a ppt. file with win32com, just unsure how to select the slide and insert an image in it, here is what I have:

def createppt():
width=10
height=10
x=10
y=10
Image = ABFLgraph()
ppt = win32com.client.Dispatch("Powerpoint.Application")
ppt.Visible = True
pptfile = ppt.Presentations.Open(file2,ReadOnly=0,Untitled=0, WithWindow=1)
Base = pptfile.Slides(2)
pic = Base.Shapes.AddPicture(Filename =Image,
    LinkToFile=True,
    SaveWithDocument=False,
    Left=x, Top=y,
    Width=width, Height=height)

Any suggestions? In the Base = pptfile.Slides(2) I was trying to select the slide number to insert the image into but this didnt work...I get this Error:

File ">", line 5, in AddPicture pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, "The specified file wasn't found.", None, 0, -2147024809), None)

Which I think means that there is an issue with how I am passing the filename/image.

like image 404
Canuk688 Avatar asked Jan 25 '26 01:01

Canuk688


1 Answers

Save your plots as image files (using pylab.savefig(), presuming you're using matplotlib), then add them to your PowerPoint slide calling slides.addpicture(). Example syntax for the addpicture function is available in the following iPython notebook: Automating Microsoft Office with Python.

like image 123
unrgnl Avatar answered Jan 26 '26 13:01

unrgnl