你需要在我看来包括图像的单元格位置。
尝试(请替换为单元格值):import win32com.client as win32
from PIL import ImageGrab
from xlrd import open_workbook
import os
excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
r.Range(r.Cells(1,1),r.Cells(8+rows,total_length)).CopyPicture()
im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')
或者,也可以使用图表对象:import win32com.client as win32
from PIL import ImageGrab
from xlrd import open_workbook
import os
excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = open_workbook('Inputs_v3.xlsm')
r = wb.sheet_by_name('Inputs')
for chart in r.Chartobjects():
//implement your custom logic here
chart.CopyPicture()
im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')
其他参考: