合并多个ppt问题

我们遇到组会时候经常会合并多人ppt,但是由于人有点多总是漏合,所以才有了这个小程序,防止自己找不到。

注意一点,下面小程序只合并ppt的内容,不合并背景图。

'''
请先安装 win32com
$ pip --default-timeout=1000 install -U pypiwin32
note: 路径要写全路径
另外输出ppt一定要先建一个空的,因为我试验 Presentation.Add()没有成功
所以需要新建一个空白ppt,命名为[周会].pptx,会生成一个[周会]2018-11-23.pptx的pptx
'''

import win32com.client, sys
from glob import glob
import argparse
import os
import datetime

parser = argparse.ArgumentParser()
parser.add_argument('--input_folder',type=str,default='C:/Users/xxx/1116/')
parser.add_argument('--out_ppt',type=str,default='E:/PycharmProjects/[周会].pptx',help='the full path and name of the out ppt')
opt = parser.parse_args()

def scan_pptx(directory,imgpostfile = ['.pptx']):
    imglist = []
    filelist = os.listdir(directory)
    for item in filelist:
        if os.path.splitext(item)[1] in imgpostfile:
            imglist.append(item)
            imglist.sort(key=lambda x: (len(x), x))
    return imglist
def join_ppt(ppt_folder,name_list,out_ppt):
    Application = win32com.client.Dispatch("PowerPoint.Application")
    Application.Visible = True
    # Create new presentation
    if not os.path.exists(out_ppt):
        print(out_ppt,' is not exist')
        exit()
    today = datetime.date.today()
    new_ppt = Application.Presentations.Open(out_ppt)
    #new_ppt = new_ppt.Slides.Add(1,12)
    files = scan_pptx(ppt_folder)
    non_files=[]
    for name in name_list:
        fname = findstr(files,name)
        if fname == None:
            non_files.append(name)
        else:
            print(fname)
            #从files中去掉某些ppt
            files.remove(fname)
            exit_ppt = Application.Presentations.Open(os.path.join(ppt_folder, fname))
            page_num = exit_ppt.Slides.Count
            num = new_ppt.Slides.InsertFromFile(os.path.join(ppt_folder, fname), new_ppt.Slides.Count, 1, page_num)
            exit_ppt.Close()
    print('the cout of the all ppt',new_ppt.Slides.Count)
    outppt_name = out_ppt[:-5]+str(today)+'.pptx'
    new_ppt.SaveAs(outppt_name)
    print('输出ppt名字:',outppt_name)
    Application.Quit()
    # 有些ppt没有在名字列表中,所以最后输出一下有些ppt没有合并,确认是否要加入到名字列表中
    print('一些ppt没有被合并,请确认是否应该加入到名字列表',files)
    print('一些人ppt没有发现',non_files)
def findstr(files,name):
    flag = False
    for fname in files:
        flag = fname.find(name)
        if flag != -1:
            return fname
    return None
if __name__ == '__main__':
    name_list = []
    join_ppt(opt.input_folder,name_list,opt.out_ppt)

你可能感兴趣的:(合并多个ppt问题)