从excel文件中提取图片

在做项目的时候有些顾客在提供数据集的时候是放在Excel中发来的,需要把图片进行提取到文件夹中。
代码如下:

from openpyxl import load_workbook
from openpyxl_image_loader import SheetImageLoader
from PIL import Image
import os

path = "D:/xxx/copy_stall/2019.xlsx" # Excel文件路径
saveDir = "D:/xxx/copy_stall/babe/"  # 图片存储路径

count =0

wb = load_workbook(path)  # 
ws = wb[wb.sheetnames[0]]#获取excel的第一个表的信息
for image in ws._images:#获取全部图片信息
  # print(image.anchor._from.col)
  # if(image.anchor._from.col == 26 ):
  count += 1
  image = Image.open(image.ref).convert("RGB")
  print(saveDir + "16" + "_" + '{:06}'.format(count) + ".jpg")
  image.save(saveDir + "16" + "_" + '{:06}'.format(count) + ".jpg")

指定输出某一列的图片

for image in ws._images:#获取全部图片信息
  
  if(image.anchor._from.col == 26 ):#当图片是26列时输出
    count += 1
    image = Image.open(image.ref).convert("RGB")
    print(saveDir + "16" + "_" + '{:06}'.format(count) + ".jpg")
    image.save(saveDir + "16" + "_" + '{:06}'.format(count) + ".jpg")

image.anchor._from是获取图片的横纵坐标。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值