学会用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学习推荐:。
(推荐操作系统:windows7系统、Python 3.9.1,DELL G3电脑。)
Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务