Question

How can I get amount of rows in Excel file via xlwt? Is it unable and I should open this file for read via xlrd just for get this info?

Was it helpful?

Solution 2

I don't think it's possible with xlwt only. Use xlrd (Sheet.nrows) or xlutils. Example from xlutils docs:

>>> from xlutils.tests.fixtures import make_sheet
>>> sheet = make_sheet((
...           ('X',' ',' ',' ',' '),
...           (' ',' ',' ','X',' '),
...           (' ',' ',' ',' ',' '),
...           ('X',' ',' ',' ',' '),
...           (' ',' ','X',' ',' '),
...           (' ',' ',' ',' ',' '),
...           ))
>>> from xlutils.margins import number_of_good_rows
>>> number_of_good_rows(sheet)
5

OTHER TIPS

I know this topic is a bit old but it's the first google result when lookink for this issue. I'm using python 3.6 with xlwt 1.2.0 and to get worksheet length I use this:

len(ws._Worksheet__rows) #care the simple then double underscore
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top