使用 python (win32com.client) 将图像插入幻灯片 [英] Insert images to powerpoint slide using python (win32com.client)

查看:110
本文介绍了使用 python (win32com.client) 将图像插入幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是将数百张图片插入并调整大小到 PowerPoint 中.我需要使用与我们公司使用的其他电源点类似的特定源格式.

I have been tasked with inserting and re-sizing several hundred images to a powerpoint. I need to use a particular source format that is similar to other power points used by our company.

我一直在尝试使用 activepython 的 win32com API,我已经找到了打开文件和创建空白幻灯片的方法.

I have been playing around with activepython's win32com API's and I have figured out how to open up a file and create a blank slide.

我的问题是我将如何插入图像并将其调整为我需要的任何大小(图像将是每页上唯一的内容).此外,我试图将我公司的主题用于背景和标题页,但这并不像在页面上获取图像并重新调整大小那么重要.

My question is how would I go about inserting an image and resizing it to whatever size I need(the images will be the only thing on each page). Also I am trying to use my company's theme for the background and title page but this is not as important as getting the images on page and re-sized.

任何帮助将不胜感激,谢谢!

any help would be greatly appreciated, thanks!

推荐答案

我从 Xavier 提到的页面中得到了这个:

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.

最好将宽度和高度指定为 -1.然后 PPT 会以它们的自然"大小插入它们(无论 PPT 可能决定什么……对目前的目的都不重要).然后,您可以读取形状的大小以确定其纵横比,并确保在更改大小时保持不变,或者您可以将形状的 .LockAspectRatio 属性设置为 true 并调整高度或宽度,另一个将自动调整以保持纵横比比例.

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.

这篇关于使用 python (win32com.client) 将图像插入幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆