使用 xlrd 搜索 excel
searching excel using xlrd
我正在尝试自学如何使用 xlrd 完成(概念上的)简单任务:
我想通过 raw_input 从用户那里获取一个字符串,然后在 excel sheet 中搜索该字符串。
找到后我希望程序只打印单元格行
这是我的非工作代码开始:
import xlrd
from xlrd import open_workbook
book = open_workbook('simple.xls')
sheet = book.sheet_by_index(0)
city = raw_input("> ")
for rowi in range(sheet.nrows):
row = sheet.row(rowi)
for coli, cell in enumerate(row):
if cell.value == city:
loc = cell.row
??????????????
cell = sheet.cell(loc, 9)
print "The Ordinance Frequency is %r" % cell.value
尝试以与循环遍历行相同的方式循环遍历列
for r in range(sheet.nrows):
for c in range(sheet.ncols):
cell = sheet.cell(r, c)
if cell.value == city:
loc = r //index of interesting row
我正在尝试自学如何使用 xlrd 完成(概念上的)简单任务:
我想通过 raw_input 从用户那里获取一个字符串,然后在 excel sheet 中搜索该字符串。
找到后我希望程序只打印单元格行
这是我的非工作代码开始:
import xlrd
from xlrd import open_workbook
book = open_workbook('simple.xls')
sheet = book.sheet_by_index(0)
city = raw_input("> ")
for rowi in range(sheet.nrows):
row = sheet.row(rowi)
for coli, cell in enumerate(row):
if cell.value == city:
loc = cell.row
??????????????
cell = sheet.cell(loc, 9)
print "The Ordinance Frequency is %r" % cell.value
尝试以与循环遍历行相同的方式循环遍历列
for r in range(sheet.nrows):
for c in range(sheet.ncols):
cell = sheet.cell(r, c)
if cell.value == city:
loc = r //index of interesting row