• 你能猜出这是什么代码


    from win32com.client import Dispatch        # 导入win32com模块的client包下的函数
    import os                        # 导入系统功能模块OS

    '''批量生成PowerPoint演示文稿中的幻灯片'''
    def PowerPoint():
        ppt = os.path.join(os.getcwd(), "titles.pptx")        # 片头模版文件
        App = Dispatch("PowerPoint.Application")            # 创建PowerPoint应用程序
        App.Visible = True                        # 显示PowerPoint窗口
        Presentation = App.Presentations.Open(ppt)            # 打开模版文件
        # 要显示的内容列表
        itemlist = [("《半壶纱》", "宋佳琦"), ("《洞庭新歌》", "Aurora"), ("《知否、知否》", "无语")]  
        itemlen = len(itemlist)                    # 节目的个数
        offset = 2            # 设置新添加幻灯片的起始页,值为:模版的片头幻灯片个数+1
            # 复制和曲目相同个数的幻灯片(由于要保留格式,所以此处只能通过合并PPT的方式实现)
        for n in range(offset, itemlen + offset):  
            # 将当前目录下的page.pptx中的幻灯片插入到当前PPT文件中
            Presentation.Slides.InsertFromFile(os.path.join(os.getcwd(), "page.pptx"), Presentation.Slides.Count, 1, 1)
        for i in range(offset, itemlen + offset):  # 循环修改每页幻灯片中的曲目名称和表演者
            item = itemlist[i - 2]
            # 修改第一个文本框的内容
            Presentation.Slides(i).Shapes(1).TextFrame.TextRange.Text = item[0]
            # 修改第二个文本框的内容
            Presentation.Slides(i).Shapes(2).TextFrame.TextRange.Text = "表演者:" + item[1]  
        outfile = os.path.join(os.getcwd(), "音乐会PPT.pptx")  # 目标文件
        Presentation.SaveAs(outfile)                    # 另存为新的PowerPoint演示文稿
        App.Quit()                            # 退出PowerPoint应用程序
        print("PPT文件已生成!文件位置为:",outfile)

    PowerPoint()  # 调用函数开始生成

  • 相关阅读:
    Kubernetes简介
    一文详解常见的基于比较的排序算法【简单易懂】
    布兰德 • 斯奈德节拍表
    Python编程陷阱(四)
    virtualbox虚拟机安装Ubuntu异常处理:FATAL: NO bootable medium found! System halted
    哈工大校园网显示IP地址错误连接不上
    想在期货市场存活 需要关注什么数据?
    Vue 组件之间的通信,动态组件和插槽
    [python][nginx][https] Nginx 服务器 SSL 证书安装部署
    图像处理之matlab的取整函数round、ceil、floor和fix
  • 原文地址:https://blog.csdn.net/s13596191285/article/details/125514304