龙空技术网

Python实用脚本系列_批量将ppt页面另存为png图片

ModelGuru陈哥 69

前言:

今天我们对“python将图片保存到文件夹中”可能比较珍视,咱们都想要分析一些“python将图片保存到文件夹中”的相关内容。那么小编同时在网络上搜集了一些对于“python将图片保存到文件夹中””的相关内容,希望兄弟们能喜欢,小伙伴们一起来了解一下吧!

批量将ppt文件页面另存为png图片

# '''# # ppt 转 png 方法一# import office# office.ppt.ppt2img(in_path  = r'D:\Temp\xxx.pptx',#                    out_path = r'D:\temp\temp_ppt2png',#                    img_type='png')# '''# ppt 转 png 方法二import osimport win32com.clientdef ppt_to_img(filePath, dirName, imgType):    '''    将 PPT 页面另存为图片格式,电脑未安装 PowerPoint 时免谈    filePath:  待转换文件的完整路径,要包含文件名    dirName:  转换后的存放目录    imgType:   图片类型    '''    # 启动 PowerPoint     app = win32com.client.Dispatch('PowerPoint.Application')    app.Visible = True # 隐藏 app 后台运行会报错    ppt = app.Presentations.Open(filePath)   # 打开 PPT 文件    ppt.SaveAs(dirName, imgType)             # 另存为    # 退出    app.Quit()# 练习函数调用,直接放调用函数内也一样def ppts_to_img(app, filePath, dirName, imgType):    ppt = app.Presentations.Open(filePath)    ppt.SaveAs(dirName, imgType)    ppt.Close()# 启动代码if __name__ == '__main__':    print('开工.........')    # 根据需要自行设置目录    # path = os.sys.path[0] # 可以提取当前脚本文件所在的当前目录    path = r'E:\Temp'    # 获取文件列表    folder_list = os.listdir(path)    # 获取指定目录下所有后缀为 ppt 或者 pptx 的文件,返回值是生成器对象    # 排除了子目录及其它类型的文件    files2 = (folder for folder in folder_list if folder.endswith(('.ppt', '.pptx')))    # 启动 PPT    app = win32com.client.Dispatch('PowerPoint.Application')    app.Visible = True # 隐藏 app 到后台运行会报错    for file in files2:        prefix   = os.path.splitext(file)[0]        fullName = os.path.join(path, file)        newPath  = os.path.join(path, prefix)        if not os.path.exists(newPath):            os.mkdir(newPath)            toJPG = 17            toPNG = 18            ppts_to_img(app, fullName, newPath, toPNG)    app.Quit()    print('老板,干完咯,喝酒去咯!')

标签: #python将图片保存到文件夹中 #python将图片保存到文件夹中怎么弄的 #python filetypeppt