Jim Chiang wrote:
> I’m trying to very simply insert a picture from a file into an excel
> spreadsheet. I know how to do this in VBA and it works fine, however
> when I try this from python I get an error. Doing a search on this
> turned up nothing.
> The code I’m using is:
> from win32com.client.dynamic import Dispatch
> xl = Dispatch( 'Excel.Application' )
> xl.Visible=1
> xl.Workbooks.Add()
> xl.ActiveSheet.Pictures.Insert("C:\a.jpg")
> Traceback (most recent call last):
> File "<pyshell#7>", line 1, in <module>
> xl.ActiveSheet.Pictures.Insert("C:\a.jpg")
> AttributeError: 'function' object has no attribute 'Insert'
> I’m not sure why I get this issue since
> ‘ActiveSheet.Pictures.Insert("C:\a.jpg")’ works fine from within Excel.
> Several internet posts from my searches also suggest to use this method.
> I’ve tried this on both Python 2.1 and 2.5 with the same results.
> Any idea what the problem is or how I can insert the picture??
> TIA,
> Jim
I suspect that Pictures is a function that returns a collection - try