I got it working!
try:#Attempt to record the fields from the excel file.
row = 10 #Set the row in excel.
#While the cell isn't 'None', keep looping.
#Excel (row,col) for navigation
while xlSht.Cells(row,1).Value != None:
print >> file, "'%s'," % xlSht.Cells(row,1).Value,
row = 1 + row
row = 10 #Set the row in excel.
#While the cell isn't 'None', keep looping.
#Excel (row,col) for navigation
while xlSht.Cells(row,1).Value != None:
print >> file, "'%s'," % xlSht.Cells(row,1).Value,
row = 1 + row
This does exactly what I want. Now perhaps, is there a prettier way to write it?
I can get file.write("'%s',") % xlSht.Cells(row,1).Value to work..
I'm just taking all the values from the cells and dumping them into a text file with single quotes and a comma (sorta like comma seperated values) that need to be on long line(like I've got it above in my working code).
Also, why doesn't 'xlSht.Cells(row + 1, 1).Value' work for this loop, but it did for the previous loop I posted to tutor?
On 9/12/06, John Fouhy <[EMAIL PROTECTED]> wrote:
On 12/09/06, Chris Hengge <[EMAIL PROTECTED]> wrote:
> I'm not sure what internal blanks means.. but I'll take a stab and say
> "no", there are going to be NO blanks once I start reading the column
> unless there are no more values to read... null or "" would be fine for
> a stopping point.
Well, basically, I'm thinking you could say something like:
for i in itertools.count(1):
if xlSht.Cells(1, i).Value in (None, ''):
maxCol = i
break
This should start at (1,1) (the top-left cell), and move right, until
it hits a blank cell, at which point it aborts.
You could do the same thing, but changing row instead of column, to
find the maximum column.
So, by "internal blanks", I meant blank cells with non-blank cells to
the right, or below.
Also, if the first row is not necessarily the longest, you would need
a bit more trickery.
> also, what is makepy.py? I'm still working through a couple books on
> python, so I haven't got all the tricks yet :]
makepy.py is a utility that comes with pythonwin. Basically it builds
python libraries corresponding to COM objects. If you do this
(one-time only), your code should run faster. Also, you will get
meaningful help(), and you can look at the code it produces to get a
quick list of all the available methods, and what arguments they
expect.
You can run it from the command line, or you can run it from the menu
of the pythonwin IDE.
--
John.
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor