query
query

Reputation: 81

Searching the string and getting the row and column value

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

Upvotes: 5

Views: 33867

Answers (2)

Sujay Narayanan
Sujay Narayanan

Reputation: 487

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,

Upvotes: 18

frogbandit
frogbandit

Reputation: 571

Say you're searching for a string s:

for row in range(sh.nrows):
    for column in range(sh.ncols):
        if s == sh.cell(row, column).value:  
            return (row, column)

Upvotes: 1

Related Questions