python合并ppt

python合并ppt

import win32com.client as win32
import os
import re

def find(s):
    pat = re.compile(r"\d+")
    result = pat.match(s)
    return int(result.group(0))

def join_ppt(path:str):
    """ :param path: ppt所在文件路径 :return: None """
    files = os.listdir(path)
    files.sort(key = find)
    Application = win32.gencache.EnsureDispatch("PowerPoint.Application")

    Application.Visible = 1
    new_ppt = Application.Presentations.Add()
    for file in files:
        abs_path = os.path.join(path, file)
        exit_ppt = Application.Presentations.Open(abs_path)
        print(abs_path)
        page_num = exit_ppt.Slides.Count
        exit_ppt.Close()
        new_ppt.Slides.InsertFromFile(abs_path, new_ppt.Slides.Count, 1, page_num)
    new_ppt.Save()  # 保存在C:\Users\Administrator\Documents\下
    Application.Quit()

join_ppt(r"C:\Users\Administrator\Desktop\test1")

部分代码转载自这里

    原文作者:he_yang_
    原文地址: https://blog.csdn.net/he_yang_/article/details/89407906
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞