import xlrd
datafile ="somefile"
workbook = xlrd.open_workbook(datafile)
sheet = workbook.sheet_by_index(0)
def get_cell_range(start_col, start_row, end_col, end_row):
return [sheet.row_slice(row, start_colx=start_col, end_colx=end_col+1) for row in xrange(start_row, end_row+1)]
print get_cell_range(0,13,2,17)
输出
[[text:u'CENTRAL',number:4.0,number:0.0],[text:u'COASTAL',number:1.0,number:1.0],[text:u'PIEDMONT',number:5.0,编号:8.0],[文字:u'STUDENT',编号:3.0,编号:4.0],[文字:u'WEST',编号:4.0,编号:4.0]]
答案 0 :(得分:1)
Sheet.row_slice()返回Cells。如果直接打印,it将包含类型信息。尽量让自己获得价值。
cells = get_cell_range(0,13,2,17)
values = [item.value for item in cells]