Search code examples
pythonexcelpython-2.7xlrdxlwt

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?


Solution

  • 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