Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中按单元格值获取列或行号_Python_Excel - Fatal编程技术网

如何在python中按单元格值获取列或行号

如何在python中按单元格值获取列或行号,python,excel,Python,Excel,如果我的Excel表格如上图所示 那么我怎样才能得到MT列的列号呢 for mt in sheet.row_values(0): print mt if mt=='MT': break 有没有像sheet.row\u values(0.colnumber)这样的函数?RickyA的也可以拼写 col_idx = -1 for idx, mt in enumerate(sheet.row_values(0)): print mt if mt=='M

如果我的Excel表格如上图所示

那么我怎样才能得到MT列的列号呢

for mt in sheet.row_values(0):
    print mt
    if mt=='MT':
        break

有没有像sheet.row\u values(0.colnumber)这样的函数?

RickyA的也可以拼写

col_idx = -1
for idx, mt in enumerate(sheet.row_values(0)):
    print mt
    if mt=='MT':
        col_idx = idx
        break
next(i for i, mt in enumerate(sheet.row_values(0)) if mt=='MT')

next
如果需要,可以提供默认值。

我们应该猜测您用于解析文件的模块吗?不,我只是想知道是否有任何方法可以帮助我通过行索引和单元格值获取colmun索引既然您正在寻找第一个,这不是简单的
表。行值(0)。索引(“MT”)