Search code examples
pythonxlrd

Read the number of rows in a range with xlrd - Python


I want to read the number of rows within a range. I have a file that has a lot of rows. I want to know the number of rows in a column range, let´s say, from column A through D.

workbook = xlrd.open_workbook(file)
sheet = workbook.sheet_by_index(0)
sheet.nrows[0:4] #I want to know the number of rows within that range, or "A{}:D{}"

If anyone knows a method to do this, please help me. Thank You!


Solution

  • You can Iterate through columns... Use loop:

    for col_idx in range(0, num_cols):  # Iterate through columns 
            cell_obj = xl_sheet.cell(row_idx, col_idx)  # Get cell object by row, col