On 2/10/2006 11:51 AM, 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??
Four problems: (1) VBA syntax instead of Python syntax (2) Not reading error message (3) Courting danger with backslashes in filenames (4) Courting danger keeping misc cruft in root directory Solution: xl.ActiveSheet.Pictures().Insert(r"C:\misc_cruft\a.jpg") HTH, John _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32