python根据excel自动生成ppt代码

系统环境

  1. 系统:window
  2. 环境:
  • python 3.7
  • pip
  • pptx
  • openpyxl
  1. 开发工具

引入需要的包

pip install openpyxl
pip install python-pptx
pip install jupyter

配置config.ini文件

[base]
basePPTpath = E:\anna\base\base-2.pptx
baseExcelPath = E:\anna\LEP#185会议议程.xlsx
targetPPTpath =E:\anna\base\LEP#185会议议程.pptx
sheetName =会议议程前页
voting=E:\anna\base\VOTING.png
backGrounBase=E:\anna\base\backgroud.png
backGroundQR=E:\anna\base\QR_CODE_BACKGROUND.png

准备文件

在这里插入图片描述
代码

import pptx
import openpyxl
import time
import  os
import math
from pptx import Presentation
from openpyxl import load_workbook
from pptx.util import Inches, Pt, Cm
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_PARAGRAPH_ALIGNMENT,MSO_AUTO_SIZE
from pptx.enum.shapes import MSO_AUTO_SHAPE_TYPE
from pptx.enum.dml import MSO_FILL_TYPE
from configparser import ConfigParser
import os
import copy
import numpy as np
import datetime, calendar
import queue


def getCurrentFriday():
    lastFriday = datetime.date.today()
    oneday = datetime.timedelta(days=1)
    while lastFriday.weekday() != calendar.FRIDAY:
        lastFriday += oneday
    return str(lastFriday.strftime("%Y.%m.%d"))

def addTimeRule(prs):
    copied_slide = prs.slides[15]
    workbook = load_workbook(filename=baseExcelPath)
    sheet = workbook["会议议程后页"]
    for j, shape in enumerate(copied_slide.shapes):
        if shape.has_table:
            shape.table.cell(0,0).text = "Type of Speech"
            shape.table.cell(0,0).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(0,0).text_frame.paragraphs[0].font.bold = True
            shape.table.cell(0,0).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(0, 0).text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
            shape.table.cell(1, 0).text = sheet.cell(row=30, column=1).value
            shape.table.cell(1, 0).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(1, 0).text_frame.paragraphs[0].font.bold = True
            shape.table.cell(1,0).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(2, 0).text = sheet.cell(row=31, column=1).value
            shape.table.cell(2, 0).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(2, 0).text_frame.paragraphs[0].font.bold = True
            shape.table.cell(2,0).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(3, 0).text = sheet.cell(row=32, column=1).value
            shape.table.cell(3, 0).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(3, 0).text_frame.paragraphs[0].font.bold = True
            shape.table.cell(3,0).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(4, 0).text = sheet.cell(row=33, column=1).value
            shape.table.cell(4, 0).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(4, 0).text_frame.paragraphs[0].font.bold = True
            shape.table.cell(4,0).text_frame.paragraphs[0].font.size = Pt(20)

            shape.table.cell(0, 1).text = sheet.cell(row=29, column=11).value
            shape.table.cell(0, 1).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(0, 1).text_frame.paragraphs[0].font.bold = True
            shape.table.cell(0, 1).text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
            shape.table.cell(0,1).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(1, 1).text = sheet.cell(row=30, column=11).value
            shape.table.cell(1, 1).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(1,1).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(2, 1).text = sheet.cell(row=31, column=11).value
            shape.table.cell(2, 1).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(2,1).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(3, 1).text = sheet.cell(row=32, column=11).value
            shape.table.cell(3, 1).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(3,1).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(4, 1).text = sheet.cell(row=33, column=11).value
            shape.table.cell(4, 1).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(4,1).text_frame.paragraphs[0].font.size = Pt(20)

            shape.table.cell(0, 2).text = sheet.cell(row=29, column=17).value
            shape.table.cell(0, 2).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(0, 2).text_frame.paragraphs[0].font.bold = True
            shape.table.cell(0, 2).text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
            shape.table.cell(0,2).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(1, 2).text = sheet.cell(row=30, column=17).value
            shape.table.cell(1, 2).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(1,2).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(2, 2).text = sheet.cell(row=31, column=17).value
            shape.table.cell(2, 2).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(2,2).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(3, 2).text = sheet.cell(row=32, column=17).value
            shape.table.cell(3, 2).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(3,2).text_frame.paragraphs[0].font.size = Pt(20)

            shape.table.cell(0, 3).text = sheet.cell(row=29, column=23).value
            shape.table.cell(0, 3).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(0, 3).text_frame.paragraphs[0].font.bold = True
            shape.table.cell(0, 3).text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
            shape.table.cell(0,3).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(1, 3).text = sheet.cell(row=30, column=23).value
            shape.table.cell(1, 3).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(1,3).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(3, 3).text = sheet.cell(row=32, column=23).value
            shape.table.cell(3, 3).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(3,3).text_frame.paragraphs[0].font.size = Pt(20)

            shape.table.cell(0, 4).text = sheet.cell(row=29, column=28).value
            shape.table.cell(0, 4).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(0, 4).text_frame.paragraphs[0].font.bold = True
            shape.table.cell(0, 4).text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
            shape.table.cell(0,4).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(1, 4).text = sheet.cell(row=30, column=28).value
            shape.table.cell(1, 4).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(1,4).text_frame.paragraphs[0].font.size = Pt(20)

            shape.table.cell(0, 5).text = sheet.cell(row=29, column=34).value
            shape.table.cell(0, 5).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(0, 5).text_frame.paragraphs[0].font.bold = True
            shape.table.cell(0, 5).text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
            shape.table.cell(0,5).text_frame.paragraphs[0].font.size = Pt(20)
            shape.table.cell(1, 5).text = sheet.cell(row=30, column=34).value
            shape.table.cell(1, 5).text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
            shape.table.cell(1,5).text_frame.paragraphs[0].font.size = Pt(20)
    copied_slide.shapes[2].text_frame.text="Shanghai L.E.P. Bilingual Toastmasters Club #185 | "+getCurrentFriday()
    copied_slide.shapes[2].text_frame.paragraphs[0].font.size = Pt(18)
    copied_slide.shapes[2].text_frame.paragraphs[0].font.color.rgb = RGBColor(242, 242, 242)
    copied_slide.shapes[2].text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.RIGHT


def duplicate_slide(pres,index):
    slide = pres.slides[index]
    blank_slide_layout = pres.slide_layouts[6] #空白页
    copied_slide = pres.slides.add_slide(blank_slide_layout)
    for shape in slide.shapes:
        el = shape.element
        newel = copy.deepcopy(el)
        copied_slide.shapes._spTree.insert_element_before(newel, 'p:extLst')
    for value in slide.part.rels.values():
        # Make sure we don't copy a notesSlide relation as that won't exist
        if "notesSlide" not in value.reltype:
            copied_slide.part.rels.add_relationship(value.reltype,value._target, value.rId)
    arrayList=np.array([0,1,2,3,4,5,6])
    # clear_shape(copied_slide,arrayList)
    return copied_slide
def addTopic(copied_slide,topic,topOrBottom):
    if(topOrBottom=="top"):
        topic_shape = copied_slide.shapes.add_shape(MSO_AUTO_SHAPE_TYPE.RECTANGLE, Cm(0.81), Cm(11.71), Cm(32.25), Cm(2.03))
    elif(topOrBottom=="bottom"):
        topic_shape = copied_slide.shapes.add_shape(MSO_AUTO_SHAPE_TYPE.RECTANGLE, Cm(0.04), Cm(9.72), Cm(33.79), Cm(2.03))
    else:
        raise Exception('log position Error')
    topic_shape.text_frame.text=topic
    # topic_shape.text_frame.auto_size=MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE
    topic_shape.fill.background()
    topic_shape.line.fill.background()
    topic_shape.text_frame.margin_bottom=Cm(0.13)
    topic_shape.text_frame.margin_top=Cm(0.13)
    topic_shape.text_frame.margin_left = Cm(0.25)
    topic_shape.text_frame.margin_right = Cm(0.25)
    para = topic_shape.text_frame.paragraphs[0]
    para.alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
    font = para.font
    font.size = Pt(72)
    font.name = 'Arial'
    font.bold = True
    font.color.rgb = RGBColor(254, 238, 159)

def addLogandTime(copied_slide,topOrBottom):

    if(topOrBottom=="top"):
        topic_shape = copied_slide.shapes.add_shape(MSO_AUTO_SHAPE_TYPE.RECTANGLE, Cm(4.23), Cm(0.90), Cm(25.40), Cm(2.54))
        topic_shape.text_frame.text ="Shanghai L.E.P. Bilingual Toastmasters Club #185 | " + getCurrentFriday()
        # topic_shape.text_frame.auto_size=MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE
        topic_shape.fill.background()
        topic_shape.line.fill.background()
        topic_shape.text_frame.margin_bottom = Cm(0.13)
        topic_shape.text_frame.margin_top = Cm(0.13)
        topic_shape.text_frame.margin_left = Cm(0.25)
        topic_shape.text_frame.margin_right = Cm(0.25)
        para = topic_shape.text_frame.paragraphs[0]
        para.alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
        font = para.font
        font.size = Pt(24)
        font.name = 'Arial'
        font.bold = False
        font.color.rgb = RGBColor(255, 255, 255)
    elif(topOrBottom=="bottom"):
        topic_shape = copied_slide.shapes.add_shape(MSO_AUTO_SHAPE_TYPE.RECTANGLE, Cm(4.23), Cm(16.15), Cm(25.40), Cm(2.54))
        topic_shape.text_frame.text = "Shanghai L.E.P. Bilingual Toastmasters Club #185"
        p=topic_shape.text_frame.add_paragraph()
        p.text = getCurrentFriday()
        topic_shape.fill.background()
        topic_shape.line.fill.background()
        topic_shape.text_frame.margin_bottom = Cm(0.13)
        topic_shape.text_frame.margin_top = Cm(0.13)
        topic_shape.text_frame.margin_left = Cm(0.25)
        topic_shape.text_frame.margin_right = Cm(0.25)
        para = topic_shape.text_frame.paragraphs[0]
        para.alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
        font = para.font
        font.size = Pt(24)
        font.name = 'Arial'
        font.bold = False
        font.color.rgb = RGBColor(255, 255, 255)
        para = topic_shape.text_frame.paragraphs[1]
        para.alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
        font = para.font
        font.size = Pt(24)
        font.name = 'Arial'
        font.bold = False
        font.color.rgb = RGBColor(255, 255, 255)
    else:
        raise Exception('log position Error')
def addtopicKey(copied_slide,topicKey,referee):
    if(referee==None):
        textbox = copied_slide.shapes.add_textbox(Cm(3.75),
                                                  Cm(8.28),
                                                  Cm(30.11),
                                                  Cm(2.03)
                                                  )
        tf = textbox.text_frame
        para = tf.paragraphs[0]
        para.text = topicKey
        # 设置字体属性
        font = para.font
        font.size = Pt(20)  # 大小
        font.name = 'Arial'  # 字体
        font.bold = False  # 加粗
        font.italic = False  # 倾斜
        font.color.rgb = RGBColor(254, 238, 159)  # 黄色
    else:
        textbox = copied_slide.shapes.add_textbox(Cm(3.75),
                                                  Cm(8.28),
                                                  Cm(30.11),
                                                  Cm(2.03)
                                                  )
        tf = textbox.text_frame
        para = tf.paragraphs[0]
        para.text = topicKey
        p = tf.add_paragraph()
        p.text=referee
        # 设置字体属性
        font = para.font
        font.size = Pt(20)  # 大小
        font.name = 'Arial'  # 字体
        font.bold = False  # 加粗
        font.italic = False  # 倾斜
        font.color.rgb = RGBColor(254, 238, 159)  # 黄色
        font = p.font
        font.size = Pt(20)  # 大小
        font.name = 'Arial'  # 字体
        font.bold = False  # 加粗
        font.italic = False  # 倾斜
        font.color.rgb = RGBColor(254, 238, 159)  # 黄色
def addQRcode(prs,back_ground_path,QR_path):
    blank_slide_layout = prs.slide_layouts[0]
    # add topic and author
    copied_slide = prs.slides.add_slide(blank_slide_layout)
    left = top = 0
    pic = copied_slide.shapes.add_picture(back_ground_path, left, top, height=prs.slide_height)
    textbox = copied_slide.shapes.add_textbox(Cm(0.77),
                                              Cm(0.82),
                                              Cm(32.35),
                                              Cm(1.79)
                                              )
    tf = textbox.text_frame
    para = tf.paragraphs[0]
    para.text = "Vote"
    # 设置字体属性
    font = para.font
    font.size = Pt(36)  # 大小
    font.name = 'Arial'  # 字体
    font.bold = True  # 加粗
    font.italic = False  # 倾斜
    font.color.rgb = RGBColor(51, 51, 51)  # 黑色
    copied_slide.shapes.add_picture(QR_path, Cm(9.38), Cm(3.96), Cm(13.45), Cm(13.45))

##添加一个slide的方法
##topicKey 'CC9', 'Ice breaker', 'Free speech'
##topic 演讲主题
##author 作者
##是否加书名号
def addSlide(BackGrounBase,prs,topicKey,topic,author,book_title_flag,topOrBottom,referee):
    blank_slide_layout = prs.slide_layouts[0]
    # add topic and author
    copied_slide = prs.slides.add_slide(blank_slide_layout)
    left = top = 0
    pic = copied_slide.shapes.add_picture(BackGrounBase,left, top, height = prs.slide_height)
    if(book_title_flag==True):
        addTopic(copied_slide,"《"+topic+"》",topOrBottom)
    else:
        addTopic(copied_slide,topic,topOrBottom)
    #addLogandTime
    addLogandTime(copied_slide,topOrBottom)
    if(author!=None):
        # sub title
        addtopicKey(copied_slide,topicKey,referee)
        # add author
        textbox = copied_slide.shapes.add_textbox(1524000,
                                                  5452870,
                                                  9144000,
                                                  914400
                                                  )
        tf = textbox.text_frame
        para = tf.paragraphs[0]
        para.text = author
        para.alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
        # 设置字体属性
        font = para.font
        font.size = Pt(28)  # 大小
        font.name = 'Arial'  # 字体
        font.bold = False  # 加粗
        font.italic = False  # 倾斜
        font.color.rgb = RGBColor(255, 255, 255)


def PREPARED(prs,sheet,BackGrounBase):
    preNum=(sheet.max_row-14-29-2)
    topicKey = ['CC9', 'Ice breaker', 'Free speech']
    subjectQ = queue.Queue(20)
    authorQ = queue.Queue(20)
    indivIndex=0
    actua_num=0
    GENERAL_EVALUATION=False
    GENERAL_index=0
    for i in range(30, sheet.max_row-9):
        check_pre=sheet.cell(row=29, column=5).value
        if(check_pre=="PREPARED SPEECH SESSION"):
            topic=sheet.cell(row=i, column=5).value
            author = sheet.cell(row=i, column=6).value
            if(topic!="INDIVIDUAL EVALUATION SESSION" and i<=(29+preNum/2) and indivIndex==0):
                suffix = (i - 30) % 3
                addSlide(BackGrounBase,prs,topicKey[suffix],topic,author,True,"top",None)
                actua_num=actua_num+1;
                subjectQ.put(topic)
                authorQ.put(author)
            elif(topic=="INDIVIDUAL EVALUATION SESSION" and indivIndex==0):
                indivIndex=i
                subjectInform= "INDIVIDUAL EVALUATION"
                addSlide(BackGrounBase,prs, " ", subjectInform, None, False,"bottom",None)
            elif(topic!="INDIVIDUAL EVALUATION SESSION" and indivIndex!=0 and i<=(indivIndex+actua_num)):
                subjectInform=subjectQ.get()
                referee=authorQ.get()
                addSlide(BackGrounBase,prs, "INDIVIDUAL EVALUATION Report for", "《"+subjectInform+"》", author, False, "top",referee)
            elif(topic!="INDIVIDUAL EVALUATION SESSION" and indivIndex!=0 and GENERAL_EVALUATION==False):
                GENERAL_EVALUATION=True
                subjectInform = "GENERAL EVALUATION"
                addSlide(BackGrounBase,prs, " ", subjectInform, None, False, "bottom",None)
            elif(topic!="INDIVIDUAL EVALUATION SESSION" and indivIndex!=0 and GENERAL_EVALUATION==True and GENERAL_index<4):
                if("General Evaluator Report"!=topic):
                    addSlide(BackGrounBase,prs, "GENERAL EVALUATION", topic, author, False, "top",None)
                else:
                    addSlide(BackGrounBase,prs," ","GENERAL EVALUATION",author,False,"top",None)
            else:
                continue
        else:
            raise Exception('EXCEL sheet 【会议议程前页】格式错误,请重新检查')

def updateppt(BackGrounBase,BackGroundQR,basePPTPath,baseExcelPath,sheetName,votingPicture,targetPath):
    prs = Presentation(basePPTPath)
    workbook = load_workbook(filename=baseExcelPath)
    sheet = workbook[sheetName]
    topicFlag = 0
    temptopic = " "
    slide = prs.slides[0]
    master_sharing = sheet.cell(row=22, column=5).value
    slide.shapes[1].text_frame.text = master_sharing
    createTime = slide.shapes[0].text_frame.paragraphs[1]
    createTime.text = getCurrentFriday()

    slide8 = prs.slides[8]
    createTime = slide8.shapes[0].text_frame.paragraphs[1]
    createTime.text = getCurrentFriday()

    slide9 = prs.slides[9]
    slide9.shapes[2].text_frame.text=sheet.cell(row=17, column=6).value
    slide9.shapes[3].text_frame.text="Shanghai L.E.P. Bilingual Toastmasters Club #185 | "+getCurrentFriday()

    slide10 = prs.slides[10]
    slide10.shapes[2].text_frame.text=sheet.cell(row=18, column=6).value
    slide10.shapes[3].text_frame.text="Shanghai L.E.P. Bilingual Toastmasters Club #185 | "+getCurrentFriday()

    slide11 = prs.slides[11]
    slide11.shapes[0].text_frame.text=sheet.cell(row=18, column=8).value
    slide11.shapes[1].text_frame.text=sheet.cell(row=18, column=9).value
    slide11.shapes[2].text_frame.text = "Shanghai L.E.P. Bilingual Toastmasters Club #185 | " + getCurrentFriday()
    slide11.shapes[2].text_frame.paragraphs[0].font.color.rgb = RGBColor(242, 242, 242)
    slide11.shapes[2].text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.RIGHT
    slide11.shapes[2].text_frame.paragraphs[0].font.size = Pt(18)

    slide12 = prs.slides[12]
    slide12.shapes[2].text_frame.text=sheet.cell(row=19, column=6).value
    slide12.shapes[3].text_frame.text="Shanghai L.E.P. Bilingual Toastmasters Club #185 | "+getCurrentFriday()

    slide13 = prs.slides[13]
    slide13.shapes[0].text_frame.text=sheet.cell(row=19, column=8).value
    slide13.shapes[1].text_frame.text=sheet.cell(row=19, column=9).value
    slide13.shapes[2].text_frame.text = "Shanghai L.E.P. Bilingual Toastmasters Club #185 | " + getCurrentFriday()
    slide13.shapes[2].text_frame.paragraphs[0].font.color.rgb = RGBColor(242, 242, 242)
    slide13.shapes[2].text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.RIGHT
    slide13.shapes[2].text_frame.paragraphs[0].font.size = Pt(18)

    slide14 = prs.slides[14]
    slide14.shapes[2].text_frame.text=sheet.cell(row=20, column=6).value
    slide14.shapes[3].text_frame.text="Shanghai L.E.P. Bilingual Toastmasters Club #185 | "+getCurrentFriday()

    #需要加时间规则
    addTimeRule(prs)

    slide16 = prs.slides[16]
    slide16.shapes[1].text_frame.text=sheet.cell(row=22, column=6).value
    slide16.shapes[1].text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
    slide16.shapes[2].text_frame.paragraphs[1].text=getCurrentFriday()

    slide17 = prs.slides[17]
    slide17.shapes[0].text_frame.text=sheet.cell(row=24, column=5).value
    slide17.shapes[2].text_frame.text=sheet.cell(row=24, column=6).value
    slide17.shapes[3].text_frame.text = "Shanghai L.E.P. Bilingual Toastmasters Club #185 | "+getCurrentFriday()

    slide18 = prs.slides[18]
    slide18.shapes[2].text_frame.text=sheet.cell(row=25, column=6).value
    slide18.shapes[3].text_frame.text = "Shanghai L.E.P. Bilingual Toastmasters Club #185 | "+getCurrentFriday()

    slide19 = prs.slides[19]
    slide19.shapes[1].text_frame.text=sheet.cell(row=27, column=6).value
    slide19.shapes[1].text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
    slide19.shapes[2].text_frame.text = "Shanghai L.E.P. Bilingual Toastmasters Club #185 | "+getCurrentFriday()

    slide8 = prs.slides[20]
    createTime = slide8.shapes[0].text_frame.paragraphs[1]
    createTime.text = getCurrentFriday()
    #备稿部分
    PREPARED(prs,sheet,BackGrounBase)
    #二维码
    addQRcode(prs,BackGroundQR,votingPicture)
    #致谢
    addSlide(BackGrounBase, prs, " ", "JOIN US", None, False, "bottom", None)
    addSlide(BackGrounBase, prs, " ", "AWARDING", None, False, "bottom", None)

    prs.save(targetPath)

if __name__ == '__main__':
    conn = ConfigParser()
    file_path=os.path.join(os.path.abspath('.'),'config.ini')
    if not os.path.exists(file_path):
        raise FileNotFoundError("文件不存在")

    conn.read(file_path)
    basePPTpath = conn.get('base', 'basePPTpath')
    baseExcelPath = conn.get('base', 'baseExcelPath')
    targetPPTpath = conn.get('base', 'targetPPTpath')
    sheetName = conn.get('base', 'sheetName')
    voting=conn.get('base', 'voting')
    BackGrounBase = conn.get('base', 'backGrounBase')
    BackGroundQR= conn.get('base', 'backGroundQR')
    updateppt(BackGrounBase,BackGroundQR,basePPTpath,baseExcelPath,sheetName,voting,targetPPTpath)

Window代码打包

pyinstaller -F operaPPT.py

Mac电脑打包python代码.

参考文档: pptx官网.

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值