#!/bin/python # -*- coding: utf-8 -*- from pptx import Presentation import copy import datetime import sys def copy_slide(prs_base, prs_add, add_index_no, base_master_no, base_layout_no): source = prs_add.slides[int(add_index_no)] dest = prs_base.slides.add_slide(prs_base.slide_masters[int(base_master_no)].slide_layouts[int(base_layout_no)]) for placeholder in dest.shapes.placeholders: if placeholder.has_text_frame and placeholder.text_frame.text == "": sp = placeholder._sp sp.getparent().remove(sp) for shape in source.shapes: newel = copy.deepcopy(shape.element) dest.shapes._spTree.insert_element_before(newel, 'p:extLst') for key, value in source.part.rels.items(): if not "notesSlide" in value.reltype and not "slideLayout" in value.reltype: dest.part.rels.add_relationship(value.reltype, value._target, value.rId) return dest PATH_PPTX = "/var/www/borg/public/file/proposal/pptx/" PATH_TEMP = "/var/www/borg/public/file/proposal/tmp/" prs_base = Presentation(PATH_PPTX + "base.pptx") try: value = sys.argv count = 0 for arg in value: if count == 0: count+=1 else: params = arg.split(":") prs_1 = Presentation(PATH_PPTX + params[0]) copy_slide(prs_base, prs_1, params[1], params[2], params[3]) del prs_1 save_name = "merged" + '_{0:%Y%m%d%H%M%S}'.format(datetime.datetime.now()) + ".pptx" prs_base.save(PATH_TEMP + save_name) print("success") print(save_name) except Exception as e: print("error") print(e)
需要安装python3, pip, python-pptx
yum install python3
cd /usr/local/src
wget wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
python3 -m pip install python-pptx