简体   繁体   中英

How can I get amount of rows in Excel file via xlwt

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM