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?

有帮助吗?

解决方案 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

其他提示

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top