读取EXCEL文件并查询

来源:互联网 发布:mac的option键 编辑:程序博客网 时间:2024/05/21 03:16
# coding=gbkimport sysimport xlrdreload(sys)sys.setdefaultencoding('utf-8')def check(data):    inp = raw_input('请输入要查询的内容:')    for x in data:        if inp in x and inp==x[0]:            return (x[1],x[2])        elif inp in x and inp==x[1]:            return (x[0],x[2])book = xlrd.open_workbook(r'C:\Users\Administrator\Desktop\510\123.xls')sheet = book.sheet_by_index(0)rowName=sheet.row_values(0)Name_index = rowName.index(u'"道具名称"')Big_index = rowName.index(u'道具大类')Small_index = rowName.index(u'道具小类')ID_index = rowName.index(u'道具ID')Max_index =rowName.index(u'叠加上限')countRow = sheet.nrowsdata=[]for i in range(1,countRow):    temp=[]    listRow = sheet.row(i)    getName = listRow[Name_index].value    getBigID = listRow[Big_index].value    getSmallID = listRow[Small_index].value    getID = listRow[ID_index].value    getMax = listRow[Max_index].value    temp.append(getName)    temp.append('%d,%d,%d' % (getBigID,getSmallID,getID))    temp.append(getMax)    data.append(temp)na,ma = check(data)

0 0
原创粉丝点击