Search code examples
pythonexcelxlrd

sheet.nrows has a wrong value - python excel file


I got a really strange problem. I'm trying to read some data from an excel file, but the property nrows has a wrong value. Although my file has a lot of rows, it just returns 2.

I'm working in pydev eclipse. I don't know what is actually the problem; everything looks fine.

When I try to access other rows by index manually, but I got the index error.

I appreciate any help.

If it helps, it's my code:

def get_data_form_excel(address):
    wb = xlrd.open_workbook(address)
    profile_data_list = []
    for s in wb.sheets():
        for row in range(s.nrows):
            if row > 0:
                values = []
                for column in range(s.ncols):
                    values.append(str(s.cell(row, column).value))
                profile_data_list.append(values)
    print str(profile_data_list)
    return profile_data_list

Solution

  • After trying some other files I'm sure it's about the file, and I think it's related to Microsoft 2003 and 2007 differences.