【发布时间】: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)
我认为这意味着我传递文件名/图像的方式存在问题。
【问题讨论】:
-
s-anand.net/blog/automating-powerpoint-with-python 是 Python 中 PPT COM 自动化的非常简单的示例。如果您正在弄清楚如何通过 COM 嵌入图像的具体步骤,您可能应该展示您目前的现有代码。
标签: python plot embed powerpoint