3
votes

I couldnt find anything in the API. Is there a way to return the row number or coordinate of a cell based on a string match? For instance: You give the script a string and it scans through the .xls file and when it finds a cell with the matching string, it returns the coordinate or row number.

2

2 Answers

7
votes
for i in range(sheet.nrows):
     row = sheet.row_values(i)
     for j in range(len(row)):
          if row[j] == search_value:
                return i,j
return None

something like that... just a basic search

0
votes

You could try the following function, thank you Joran

def look4_xlrd (search_value, sheet) :
lines = []
columns = []
for i in range (sheet.nrows) :
    row = sheet.row_values(i)
    for j in range(len(row)) :
        if row[j] == search_value :
            lines.append(i)
            columns.append(j)
    del row
return lines, columns