python 合并多个PPT

发布时间 2023-04-05 21:10:24作者: 大话人生
# encoding=utf8
#-*-coding:utf-8 -*-

# pip install aspose.slides -i https://pypi.tuna.tsinghua.edu.cn/simple

import aspose.slides as slides


from pptx import  Presentation  #导入PPT库
import win32com.client, sys
from glob import glob

# 打開第一張PPT
with slides.Presentation("1.pptx") as pres1:
    # 打開第二個PPT
    with slides.Presentation("2.pptx") as pres2:
        # 循環播放幻燈片
        for slide in pres2.slides:
            # 克隆幻燈片
            pres1.slides.add_clone(slide)

            # 保存合併的 PPT
        pres1.save("combined.pptx", slides.export.SaveFormat.PPTX)


for i in range(3,50):
    with slides.Presentation("combined.pptx") as pres1:
        # 打開第二個PPT
        with slides.Presentation("%s.pptx"%str(i)) as pres2:
            # 循環播放幻燈片
            for slide in pres2.slides:
                # 克隆幻燈片
                pres1.slides.add_clone(slide)

                # 保存合併的 PPT
            pres1.save("combined.pptx", slides.export.SaveFormat.PPTX)
            print("保存第%s个"%str(i))


# def join_ppt(ppt_folder,new_PPT):
#     Application = win32com.client.Dispatch("PowerPoint.Application")
#     Application.Visible = True
#     # Create new presentation
#     new_ppt = Application.Presentations.Add()
#
#     files = glob(ppt_folder)
#     for f in files:
#         # Open and read page numbers
#         exit_ppt = Application.Presentations.Open(f)
#         page_num = exit_ppt.Slides.Count
#         exit_ppt.Close()
#         num = new_ppt.Slides.InsertFromFile(f, new_ppt.Slides.Count, 1, page_num)
#
#     Presentation.Save(new_PPT)
#     Application.Quit()


# if __name__ == '__main__':
#     ppt_folder = r"D:\PycharmProjects\xiaoxiaomu\制作PPT\49\ppt"
#     new_PPT = "nnn.pptx"
#     # print(sys.argv[1])
#     join_ppt(ppt_folder,new_PPT)

# # 打開第一張PPT
# with slides.Presentation("1.pptx") as pres1:
#     # 打開第二個PPT
#     with slides.Presentation("2.pptx") as pres2:
#         # 循環播放幻燈片
#         for slide in pres2.slides:
#             # 克隆幻燈片
#             pres1.slides.add_clone(slide)
#
#             # 保存合併的 PPT
#         pres1.save("combined.pptx", slides.export.SaveFormat.PPTX)