Newbie Excel question

Fabrizio facelle at jumpy.it
Sun Jan 28 15:52:36 EST 2001


Hi,

Newbie, Python2.0, Windows 98, Win32-All, MS Excel97.


Experimenting with Python and Excel, I have found this example on the web :


# this example starts Excel, creates a new workbook,
# puts some text in the first and second cell
# closes the workbook without saving the changes
# and closes Excel.  This happens really fast, so
# you may want to comment out some lines and add them
# back in one at a time ... or do the commands interactively

from win32com.client import Dispatch

xlApp = Dispatch("Excel.Application")
xlApp.Visible = 1
xlApp.Workbooks.Add()
xlApp.ActiveSheet.Cells(1,1).Value = 'Python Rules!'
xlApp.ActiveWorkbook.ActiveSheet.Cells(1,2).Value = 'Python Rules 2!'
xlApp.Close(SaveChanges=0)
xlApp.Quit()
del xlApp



If I run it the program opens an Excel sheet, writes something in the cells,
but it fails to close !
This is what I get :


Traceback (innermost last):
  File "C:\Utili\Programmazione\Python\Programmi\excel.py", line 16, in ?
    xlApp.Close()
  File "C:\Python20\win32com\client\dynamic.py", line 435, in __getattr__
    raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: Excel.Application.Close


Any help ?

Thanks in advance.

Fabrizio C.













More information about the Python-list mailing list