简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM