# 这个电脑打开就是全黑
#coding:utf-8
import win32com.client as win32
from PIL import ImageGrab
excel = win32.Dispatch('Excel.Application')
excel.Visible = False
excel.DisplayAlerts = False
wb = excel.Workbooks.Open('结果输出-2021-08-24.xls')
ws = wb.Worksheets('统计')
ws.Range('A1:B7').CopyPicture()
ws.Paste()
pic = ws.pictures[0]
pic.Copy()
img = ImageGrab.grabclipboard()
if img.mode == "P":
img = img.convert('RGB')
else:
pass
img.save('pic1.jpeg')
# 如果直接保存png,电脑打开预览是正常的,但发送微信消息图片是全黑的
pic.Copy()
img = ImageGrab.grabclipboard()
img.save('pic1.png')
PIL截图excel单元格,为什么保存后全黑呢?如下图只看到了excel一点点边框