Inaccurate row count in Excel
sample Excel: sample.xlsx
my test code:
import openpyxl
import pylightxl
import xlrd
def openpyxl_count(path):
"""
Counts the number of rows in an Excel file with openpyxl.
"""
wb = openpyxl.load_workbook(path)
sheet = wb.active
return sheet.max_row
def pylightxl_count(path):
"""
Counts the number of rows in an Excel file with pylightxl.
"""
db = pylightxl.readxl(path)
ws = db.ws(db.ws_names[0])
return ws.maxrow
def xlrd_count(path):
"""
Counts the number of rows in an Excel file with xlrd.
"""
wb = xlrd.open_workbook(path)
sheet = wb.sheet_by_index(0)
return sheet.nrows
if __name__ == '__main__':
excel_path = 'sample.xlsx'
print(openpyxl_count(excel_path))
print(pylightxl_count(excel_path))
print(xlrd_count(excel_path))
The result is strange:
14 ❎
10 ✔️
10 ✔️