关于合成 ppt 的需求
此前遇到一个需求需要合成 ppt,在网上找了一番经过测试终于实现啦!代码如下
import win32com.client as win32
import os
import re
import time
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()
new_ppt.SaveAs(r':\Users\xxx\Desktop\合并后.ppt')
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()
print(2)
time.sleep(2)
new_ppt.Slides.InsertFromFile(abs_path, new_ppt.Slides.Count, 1, page_num)
new_ppt.SaveAs(r':\Users\xxx\Desktop\合并后.ppt') # 保存在C:\Users\Administrator\Documents\下
Application.Quit()
join_ppt(r’C:\Users\xxx\Desktop\ppt’)
这个不错啊