Python实现将Excel表格转换为图片保存功能

一、引入 excel2img 库,没有的话使用 pip install excel2img进行安装

二、采用如下方法进行图片生成

excel文件名为:111.xlsx

excel表格里面的sheet名称列表为 ['Sheet1', 'Sheet2']

最终保存为以sheet名称.png的图片

支持跨表格合并项

import excel2img

def out_img(excel_file, sheet_list):
    try:
        print("开始截图,请耐心等待。。。")
        for i in range(len(sheet_list)):
            # sheet_list[i] + ".png" 为保存的图片名称(以sheet名称.png命名)
            excel2img.export_img(excel_file, sheet_list[i] + ".png", sheet_list[i], None)
    except Exception as e:
        print("截图失败!", e)


if __name__ == '__main__':
    file = '111.xlsx'
    sheet_list = ['Sheet1', 'Sheet2']
    out_img(file, sheet_list)

表格原图:

保存效果图:

作者:lytcreate.

物联沃分享整理
物联沃-IOTWORD物联网 » Python实现将Excel表格转换为图片保存功能

发表回复