[Q] Examples for Excel?

Robert Citek rwcitek at uci.edu
Thu May 18 01:57:34 EDT 2000


Hello Peter,

At 08:35 AM 5/18/00 -0700, Daehyok Shin wrote:
>Would you recommend any information about how to manipulate Excel with
>python?
>Thanks.
>
>Peter

I strongly recommend the "Python Programming on Win32" by Mark Hammond &
Andy Robinson.  Visit http://www.oreilly.com/catalog/pythonwin32

Here is some sample code:

# 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

# raw_input("press Enter ...")

Hope this helps
- Robert





More information about the Python-list mailing list