我的任务是在幻灯片中插入数百张图像并调整其大小。
我需要使用与我们公司使用的其他幻灯片类似的特定源格式。
我一直在使用 activepython 的 win32com API,并且已经弄清楚如何打开文件并创建空白幻灯片。
我的问题是我将如何插入图像并将其大小调整为我需要的任何大小(图像将是每个页面上唯一的东西)。另外,我尝试使用我公司的主题作为背景和标题页,但这并不像将图像放在页面上并重新调整大小那么重要。
任何帮助将不胜感激,谢谢!
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.
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!
发布评论
评论(4)
我从 Xavier 提到的页面中得到了这个:
如果你的原始图像是正方形的,那么这将起作用;否则,就会扭曲它们。
最好将宽度和高度指定为 -1。然后 PPT 将以“自然”大小插入它们(无论 PPT 可能决定什么......对于当前目的来说并不重要)。然后,您可以读取形状的大小以确定其纵横比,并确保在更改大小时保持不变,或者您可以将形状的 .LockAspectRatio 属性设置为 true 并调整高度或宽度,另一个将自动调整以保持纵横比比率。
I got this from the page Xavier referred to:
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.
您应该按照所述使用 Shapes.AddPicture 这里(此 损坏的链接):
请注意,“选择文件”选项会生成一个文件路径用“/”而不是“”,您可能需要用后者替换前者。
You should use Shapes.AddPicture as described here (archived version of this broken link):
Note that the "choose file" option produces a file path with '/" rather than '' and you may need to replace the former by the latter.
首先,我会在使用 PIL python 图像库插入之前先调整它们的大小。总的来说,处理任何办公室图像处理对我来说都是很糟糕的,所以我不推荐它。
其次,在 PowerPoint 帮助或在线中找到的
VBA
中的对象模型示例通常足以让您从记忆中获得很长的内容,插入非常容易 -
但是确切的位置我不记得了,恐怕我这里没有ppt可以尝试。如果以后有机会我会发布一些参考资料
祝文档好运
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 wayfrom memory the insert was pretty easy -
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
我同意已接受的答案。我想指出的是,我需要在 FileName 字符串前面加上“r”前缀,以将反斜杠视为文字字符。通过用双反斜杠替换单反斜杠来转义反斜杠也可以。 @vestland 这可能会有帮助
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