现在大部分读取excel中的图片都是通过将xlsx文件压缩,然后读取,本文可以通过python的包来读取,相比之下代码更简洁更方便。
pip install pillow
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()