openpyxl:插入一张图片报错You must install PIL to fetch image objects
from openpyxl import Workbook
from openpyxl.drawing.image import Image
wb = Workbook()
ws = wb.active
#插入指定位置 一张图片
img=Image(‘logo.jpg’)
ws.add_image(img,‘A5’)
wb.save(‘group.xlsx’)
报错如下
ImportError: You must install PIL to fetch image objects
解决办法1:cmd 里执行 pip install pillow
办法2:pycharm里 file>setting>project interpreter 点击加号,弹出界面搜索pillow, 安装installing
再次执行即可
PS:pil是只支持到python2.7,新版使用pillow,这是python处理图像的标准库