@wuxin1994
2017-10-08T11:28:28.000000Z
字数 1647
阅读 1008
python
代码如下:
import xlrdimport osprint('------------------------------------------------------------')file = 'file_in.xlsx'#需要读取的文件data = xlrd.open_workbook(file) #打开表格文件sheet = data.sheets()[0] #得到第一个表格rows = sheet.row_values(0)#得到第一行的关键字#colume = sheet.col_valuesprint('------------------------------------------------------------')print("下面是可查询字段描述:")row_number = 0for row in rows:print(row_number,'--------',row.strip().replace("\r",'').replace('\n',''))row_number = row_number + 1print('------------------------------------------------------------')print("请输入查询的关键字对应的代码(0 ~",row_number-1,"):",end=' ')while(True):row_chose = int(input())if row_chose<= row_number -1 and row_chose >= 0:breakelse:print("数字有误,请重新输入查询的关键字对应的代码(0 ~",row_number-1,"):",end=' ')print('------------------------------------------------------------')my_queues = sheet.col_values(row_chose)print("查询结果:",'\n',my_queues)print('------------------------------------------------------------')print("是否进一步查询?Y/N",end=' : ')cha = input()if cha != 'Y' and cha != 'y':os._exit(0)print('------------------下面是按照条件查询------------------------------------------')if row_chose == 0 or row_chose == 1:flag = Trueprint("请输入查询的",rows[row_chose],"的名称:",end='')while(flag):name = input()for single in my_queues:if single == name:flag = Falseindex = my_queues.index(name)print(sheet.row_values(index))if flag == True:print("有误!请重新输入查询的",rows[row_chose],"的名称:",end='')else:print("请输入查询",rows[row_chose].strip().replace("\r",'').replace('\n',''),"的范围:")max = float(input("请输入最大值:"))min = float(input('请输入最小值:'))if max < min:max,min = min,maxfor single in my_queues:try:if float(single) <= max and float(single) >= min:print(sheet.row_values(my_queues.index(single)))except:pass
