• 利用python3将已有的某几个pptx文件的某些slides来生成新的pptx文件的范例


    #!/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

  • 相关阅读:
    python使用阿里云oss-sdk
    flask-文件上传的使用
    flask-migrate的基本使用
    flask-script的基本使用
    flask-sqlalchemy的基本使用
    alembic的常用参数
    sqlchemy查询的其他操作
    orm层面的删除的注意事项
    C#获取数据库中的Instance
    SOA Demo
  • 原文地址:https://www.cnblogs.com/gaoBlog/p/12263375.html
Copyright © 2020-2023  润新知