5

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

1
  • 2
    You can add your code that you tried to the question, to make it more clear and understandable. Commented Aug 19, 2015 at 8:29

2 Answers 2

18

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,

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

1 Comment

dood you dont have to call me sir. I am your friend enjoy. Kindly Upvote if it helped.
1

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)

1 Comment

If my condition if cell.value == "particularString" : evaluates to be true, then I want to pick the value in the cell next to it. How to do that?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.