Searching the string and getting the row and column value

query picture query · Aug 19, 2015 · Viewed 26k times · Source

How to search the particular string in the excel sheet and getting the row and column value of that particular string in the excel sheet using xlrd in python? Can any one help me please?

import xlrd
workbook = xlrd.open_workbook("1234.xls")
worksheet = workbook.sheet_by_name('firstpage')

only this much i tried

Answer

I think this is what you are looking for , Here you go,

from xlrd import open_workbook
book = open_workbook(workbookName)
for sheet in book.sheets():
    for rowidx in range(sheet.nrows):
        row = sheet.row(rowidx)
        for colidx, cell in enumerate(row):
            if cell.value == "particularString" :
                print sheet.name
                print colidx
                print rowidx

best,