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 Answers
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
2 Comments
Blainer
Im getting this error
File "mp3.py", line 22 return i,j SyntaxError: 'return' outside functionJoran Beasley
well its not meant to be a direct copy and paste you need to put it in a function and set the sheet value by extracting the correct sheet from the workbook i think its like woorkbook.getsheetbyindex(0)
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