【问题标题】:How do I embed a python plot chart (or image) in ppt and refresh it如何在ppt中嵌入python绘图图表(或图像)并刷新它
【发布时间】:2014-07-20 17:45:24
【问题描述】:

我可以打开一个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 was not found.", None, 0, -2147024809), None)

我认为这意味着我传递文件名/图像的方式存在问题。

【问题讨论】:

标签: python plot embed powerpoint


【解决方案1】:

将您的绘图保存为图像文件(使用 pylab.savefig(),假设您使用的是 matplotlib),然后调用 slides.addpicture() 将它们添加到您的 PowerPoint 幻灯片中。以下 iPython 笔记本中提供了 addpicture 函数的示例语法:Automating Microsoft Office with Python

【讨论】:

  • 在这里我重新编辑了问题,向您展示我一直在使用的代码。您的原始链接有所帮助,但仍然无法在其中获取图像。
  • 实际上我将绘图保存为 png 图像。完美运行!
猜你喜欢
  • 1970-01-01
  • 2017-01-14
  • 1970-01-01
  • 2011-05-07
  • 2012-06-22
  • 1970-01-01
  • 2016-10-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多