Excel Object Model

david brochu jr brochu121 at gmail.com
Fri Mar 10 17:07:42 CET 2006


I am trying to automate Excel and I cant seem to find out much relating to
it's object model (in relation to Python)..seems as if its mostly covered by
C and VB. Can anyone point me in the right direction? I am able to open
excel, add information to cells, and then save and close the book opened. I
was looking to get into formatting of cells, formulas, etc.

Below is the code i have now...any responces would help.

import PAM
import time
from win32com.client import Dispatch    #this is needed to open an Excel
f = open('c:\python24\scripts\urls.txt','r')  #opens list of urls to be
xlApp = Dispatch("Excel.Application")
xlApp.Visible = 0
Row = 1

for x in f:      #run this for every url in txt file.
 ie = IE_Invoke(x)
 starttime = time.clock()   #get timestamp at IE startup
 wait(ie)     #wait for IE to completetly load page
 stoptime = time.clock()    #get timestamp at IE completion
 elapsed = stoptime-starttime   #calculate the runtime
 xlApp.ActiveSheet.Cells(Row,1).Value = x
 xlApp.ActiveWorkbook.ActiveSheet.Cells(Row,2).Value = elapsed
 Row = Row+1

xlApp.ActiveWorkbook.ActiveSheet.SaveAs('c:\\test_results\dave.xls') #save
results to excel book
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060310/a9bf2687/attachment.html>

More information about the Python-list mailing list