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")
部分代码转载自这里