Excel Object Model
david brochu jr
brochu121 at gmail.com
Fri Mar 10 11:07:42 EST 2006
Hello,
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
file
execfile('c:\\Python24\\scripts\\PAM.py')
f = open('c:\python24\scripts\urls.txt','r') #opens list of urls to be
tested
xlApp = Dispatch("Excel.Application")
xlApp.Visible = 0
xlApp.Workbooks.Add()
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
ie.QUIT()
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
xlApp.Quit()
-------------- 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