我可以打开ppt。使用 win32com 文件,只是不确定如何选择幻灯片并在其中插入图像,这是我所拥有的:
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)
有什么建议吗?在 Base = pptfile.Slides(2) 中,我试图选择要插入图像的幻灯片编号,但这没有用...我收到此错误:
文件“>”,第 5 行,在 AddPicture 中 pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, "The specified file wasn't found.", None, 0, -2147024809), None)
我认为这意味着我传递文件名/图像的方式存在问题。
最佳答案
将绘图保存为图像文件(使用 pylab.savefig(),假设您使用的是 matplotlib),然后调用 slides.addpicture() 将它们添加到 PowerPoint 幻灯片中。以下 iPython 笔记本中提供了 addpicture 函数的示例语法:Automating Microsoft Office with Python .
关于python - 如何在 ppt 中嵌入 python 图表(或图像)并刷新它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23963513/