首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用python将图像从ppt文件复制并粘贴到另一个ppt文件。

使用python将图像从ppt文件复制并粘贴到另一个ppt文件。
EN

Stack Overflow用户
提问于 2020-01-13 09:41:47
回答 1查看 207关注 0票数 0

我使用下面的代码将图像从一个ppt复制到另一个ppt.but,它不起作用。

代码语言:javascript
复制
ppt = win32com.client.Dispatch('Powerpoint.Application')
ppt1 = ppt.Presentations.Open("path\\temp.pptx")
ppt2 = ppt.Presentations.Open("path\\2paste.pptx")
ppt1.slide.Shapes.Copy()
ppt2.slide.Shapes.Paste()

这段代码打开了两个ppt,但它没有复制图像。

EN

回答 1

Stack Overflow用户

发布于 2022-05-13 14:45:45

使用Aspose.Slides for Python,您可以轻松地将任何形状从演示文稿复制到另一个表示。下面的代码示例向您展示了如何做到这一点:

代码语言:javascript
复制
import aspose.slides as slides

file_name1 = "temp.pptx"
file_name2 = "2paste.pptx"

with slides.Presentation(file_name1) as presentation1:
    with slides.Presentation(file_name2) as presentation2:

        # Get the first shape from the first slide, for example.
        first_shape = presentation1.slides[0].shapes[0]

        # Clone the shape and add the clone to the second presentation.
        presentation2.slides[0].shapes.add_clone(first_shape)

        # Save the second presentation.
        presentation2.save(file_name2, slides.export.SaveFormat.PPTX)

这是一个付费库,但您可以获得评估所有功能的临时许可证。我是Aspose的一个支持开发人员。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59713946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档