I am trying to copy an image from an excel named Inputs_v3 and sheet named Inputs and save. The code is as follows`
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.CopyPicture()
im = ImageGrab.grabclipboard()
im.save('somefile.png','PNG')
` The error is as follows
'Attribute error: 'Sheet' object has no attribute 'CopyPicture''
Please suggest where I am doing wrong.Thanks in advance
xlrdpackage, which have nothing to do with each other. You've setexcelto be a reference to the Excel app but then you don't do anything with it. I'm not fully familiar with either xlrd or the Excel COM model but it looks as ifCopyPictureis a method you need to call on the Excel worksheet object, not the xlrdsheet_by_nameobject. If you can get the picture using xlrd do that and don't use COM, otherwise use COM and you don't need xlrd.