Insert images to powerpoint slide using python (win32com.client)

自古美人都是妖i 提交于 2019-12-04 12:44:20

I got this from the page Xavier referred to:

Pict1 = Slide1.Shapes.AddPicture(FileName=pictName, LinkToFile=False, SaveWithDocument=True, Left=100, Top=100, Width=200, Height=200)

That will work if your original images are square; otherwise, it will distort them.

Better to specify -1 for the width and height. Then PPT will insert them at their "natural" size (whatever PPT might decide that is ... not important for present purposes). Then you can read the shape's size to determine its aspect ratio and make sure that stays constant if you change the size or you can set the shape's .LockAspectRatio property to true and adjust either height or width and the other will auto adjust to maintain the aspect ratio.

you should use Shapes.AddPicture as described here http://www.gossamer-threads.com/lists/python/python/754236

you cad sir - take that

Firstly I would resize them first before insertion using PIL python imaging library. In general mucking about with any office image processing has been uniformly awful for me so I would not recommend it.

secondly the object model examples in VBA found in PowerPoint help or online are usually all you need to get a long way

from memory the insert was pretty easy -

ppt.slide.ImageFromFile("path")

however exact positioning I do not remember and I am afraid I don't have ppt here to try out. If I get achance later I will post some references

Good luck with the docs

I agree with the accepted answer. I would like to point out that I needed to prefix the FileName string with an 'r' to treat the backslashes as literal characters. Escaping the backslashes by replacing single backslashes with double also works. @vestland this may be helpful

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!