Python如何读取excel中的图片
学会用Python提取word图片的小伙伴,今天又来学提取excel图片的方法啦。本期文章将通过python的包来提取,对比以往的代码更加简洁方便。
环境准备:
python3
pillow
pip install pillow
pypiwin32
pip install pypiwin32
代码
from PIL import ImageGrab import win32com.client as win32 excel = win32.gencache.EnsureDispatch('Excel.Application') workbook = excel.Workbooks.Open(r'C:\Users\file.xlsx') for sheet in workbook.Worksheets: for i, shape in enumerate(sheet.Shapes): if shape.Name.startswith('Picture'): shape.Copy() image = ImageGrab.grabclipboard() image.save('{}.jpg'.format(i 1), 'jpeg') excel.Quit()
注意事项
有些xlsx文件可能读取不了,试试换成xls格式
程序运行前不可以有其他程序打开excel文件
今天读取excel图片的方法比较简单,下期还有读取pdf图片的方法,大家不要错过哦~更多Python学习推荐:JQ教程网Python大全。
您可能感兴趣的文章:
Python如何读取excel中的图片
python如何对excel数据进行处理
PHP如何读取Excel内的图片(附代码)
python怎么读取excel表格
利用php实现读取excel中的图片
python怎么读取和写入excel表格
python怎么读取excel中的数值
Python如何操作excel
PHP高性能Excel扩展1.2.8发布,文件读取数据类型可控!
python语言如何对图片进行二值化处理