合并PPTX演示文稿时,AttributeError:Open.Close错误

发布于 2025-01-26 08:12:49 字数 1065 浏览 3 评论 0原文

我正在尝试使用@@@ zeynel 这是以下功能:

    def mergePresentations(inputFileNames, outputFileName):

        Application = win32com.client.Dispatch("PowerPoint.Application")
        outputPresentation = Application.Presentations.Add()
        outputPresentation.SaveAs(outputFileName)

        for file in inputFileNames:
            currentPresentation = Application.Presentations.Open(file)
            currentPresentation.Slides.Range(range(1, currentPresentation.Slides.Count + 1)).copy()
            Application.Presentations(outputFileName).Windows(1).Activate()
            outputPresentation.Application.CommandBars.ExecuteMso("PasteSourceFormatting")
            currentPresentation.Close()

        outputPresentation.save()
        outputPresentation.close()
        Application.Quit()

但是我不断收到以下错误: attributeError:Open.Close 如果ppt文件未关闭Win32COM库并停止整个合并过程。 关于问题的原因以及如何解决的任何想法吗?

I am trying to use the function proposed by @Zeynel which is the following function:

    def mergePresentations(inputFileNames, outputFileName):

        Application = win32com.client.Dispatch("PowerPoint.Application")
        outputPresentation = Application.Presentations.Add()
        outputPresentation.SaveAs(outputFileName)

        for file in inputFileNames:
            currentPresentation = Application.Presentations.Open(file)
            currentPresentation.Slides.Range(range(1, currentPresentation.Slides.Count + 1)).copy()
            Application.Presentations(outputFileName).Windows(1).Activate()
            outputPresentation.Application.CommandBars.ExecuteMso("PasteSourceFormatting")
            currentPresentation.Close()

        outputPresentation.save()
        outputPresentation.close()
        Application.Quit()

However I keep getting the following error:
AttributeError: Open.Close
Where the ppt file Does not close by the win32com library and stops the whole merging process.
Any idea about the cause of the problem and how to solve?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文