Reputation: 20756
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?
Upvotes: 1
Views: 4035
Reputation: 1910
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
Upvotes: 4
Reputation: 6794
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
Upvotes: 0