from itertools import product
def value_from_key(sheet, key):
for row_index, col_index in product(xrange(sheet.nrows), xrange(sheet.ncols)):
if sheet.cell(row_index, col_index).value == key:
return sheet.cell(row_index+1, col_index).value
value = value_from_key(sheet, 'COLOR')
必须向下搜索列,直到找到
COLOR
,然后在下一行中获取值。如果您知道键在偶数或奇数行中,则可以使用
xrange(0, sheet.nrows, 2)
或xrange(1, sheet.nrows, 2)
。编辑:也更新为搜索列。
相关问题 更多 >
编程相关推荐