Reading .xls file data by python string

I want to read .xls file data line by line using the value of any particular cell.

Consider the main column: ID, Name, Address, Age, Marks, Branch, these are the main fields. Now I want to access the entire line whose (i == 4). I want to access a row using the value of a specific cell.

Here I tried some

import xlrd
workbook = xlrd.open_workbook('sheet2.xls')
worksheet = workbook.sheet_by_name('Sheet1')
num_rows = worksheet.nrows - 1
num_cells = worksheet.ncols - 1
curr_row = -1
while curr_row < num_rows:
    curr_row += 1
    row = worksheet.row(curr_row)
    print 'Row:', curr_row
    curr_cell = -1
    while curr_cell < num_cells:
        curr_cell += 1
        # Cell Types: 0=Empty, 1=Text, 2=Number, 3=Date, 4=Boolean, 5=Error, 6=Blank
        cell_type = worksheet.cell_type(curr_row, curr_cell)
        cell_value = worksheet.cell_value(curr_row, curr_cell)
        print ' ', cell_type, ':', cell_value

So, I get the output as

Row: 8
        2 : 96.0
        1 : Robert
        1 : Honore
        1 : 607-829-7943
        2 : 56.0
        1 : Faye
        1 : Wight
        1 : Faye.A.Wight@mailinator.com

Thus, it prints the entire line in this format. But I want to access the string by value. We can get the cell value using cell_value = workheet.cell_value (1, 1), but how to get the row number for this cell value. And I want to get the whole line using a condition like (id == 5) or (age == 17) Please help me figure this out.

+4
1

, , "", xlrd. . .

, . , - , .

+2

Source: https://habr.com/ru/post/1542733/


All Articles