Entry
Can I access an excel (.xls) file via com without having excel loaded on that machine?
Where can I find information about how to manipulate Excel with Python?
Sep 20th, 2000 16:50
Kevin Dahlhausen, unknown unknown, Eric Hagemann, Scott
Read Hammond's & Robinson's "Programming Python in Win32". There is a
very good headstart there with an example of a class that eases the
interaction w/Excel via COM. Next get "Writing Excel Macros" by
O'Reilly. It is all about how to program Excel via Visual Basic but
translates very well into Python COM.
Visit http://www.oreilly.com/catalog/pythonwin32
If you can't afford to buy it, it seems you can view it at
http://www.netlibrary.com . It's a neat site that allows you to "check
out" books for a period of time (usually 24 hours at a time) and read
them online. The only drawback is they only allow so many "check outs"
of each book so it may or may not be available to read.
Here is an exact URL:
http://www.netlibrary.com/SUMMARY.ASP?EV=1239265&ID=24666&advquery=
and chapter 9 is the main Excel chapter.
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 ...")
9/20/00
You can find the file <i>vbaxl8.hlp</i> on the Office CD. It is a help
file the documents the Excel COM interface.