3

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 2

7
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

Sign up to request clarification or add additional context in comments.

2 Comments

Im getting this error File "mp3.py", line 22 return i,j SyntaxError: 'return' outside function
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)
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.