Python 搜索字符串并获取行和列值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32090002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Searching the string and getting the row and column value
提问by query
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?
如何在excel表中搜索特定字符串并使用xlrd
python获取excel表中该特定字符串的行和列值?任何人都可以帮助我吗?
import xlrd
workbook = xlrd.open_workbook("1234.xls")
worksheet = workbook.sheet_by_name('firstpage')
only this much i tried
我只试过这么多
采纳答案by True if u_believe else False
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,
最好的事物,
回答by frogbandit
Say you're searching for a string s
:
假设您正在搜索一个字符串s
:
for row in range(sh.nrows):
for column in range(sh.ncols):
if s == sh.cell(row, column).value:
return (row, column)