trying to parse to Excel...

Ben btjenkins at att.net
Thu May 23 15:33:24 EDT 2002


I am trying to create a simple script that will open a file (based
upon date) in a default directory and convert it to an Excel
spreadsheet.  This file will contain hundreds of lines of text - each
line will have approximately 18 items separated by commas.

This is the code I have developed so far:
from win32com.client import Dispatch
import string, sys

xlApp = Dispatch("Excel.Application")
xlApp.Visible = 1
xlApp.Workbooks.Add()

file=open("Test.txt", "r")
lines=file.readlines()
file.close()
x=1
y=1
for line in lines:
    parms=string.split(line, ",")    
    parms[0]
    for i in xrange(18):        
        xlApp.ActiveWorkbook.ActiveSheet.Cells(x,y).Value = parms[i]
        y=y+1
    x=x+1
    y=1

The script finds the file, opens Excel and populates the first row. 
BUT, it does not continue to loop through the file and populate the
other rows.  I am relatively new to Python and would appreciate any
advice that you may have.  Should you need additional information,
please let me know.

With much thanks,
Ben



More information about the Python-list mailing list