openpyxl识别excel中的图片并保存

from openpyxl import load_workbook

workbook = load_workbook(r"C:\Users\ben_ma\Desktop\新建 XLSX 工作表.xlsx")

num = 1
for sheet_name in workbook.sheetnames:
    worksheet = workbook[sheet_name]
    for image in worksheet._images:
        img_data = image._data()

        # 保存图像的二进制数据为文件
        with open(f'image_{num}.jpg', 'wb') as f:
            f.write(img_data)
        num += 1
posted @ 2023-09-11 14:48  冰柠檬檬  阅读(306)  评论(0编辑  收藏  举报