搜索字符串并获取行和列的值 [英] Searching the string and getting the row and column value

查看:170
本文介绍了搜索字符串并获取行和列的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用python中的 xlrd 在excel表中搜索特定的字符串,并获取excel表中该特定字符串的行和列值?可以有人帮我吗?

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')

只有这么多我尝试过

推荐答案

我认为这是你正在寻找的,你去,

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

最好,

这篇关于搜索字符串并获取行和列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆