#coding:GBK import xlrd import xlwt import time def read_excel(c): if c==0: print "使用率排名:" for i in range(1,sheet.nrows): lie[sheet.cell(i,c).value.encode(‘GBK‘)] = sheet.cell(i,c+1).value*(100/50) i = i+1 newlie = sorted(lie.iteritems(),key = lambda d:d[1],reverse = True) for i in range(0,len(newlie)): print newlie[i][0]+":"+str(newlie[i][1])+"分," , i = i+1 print "\n" return print sheet.cell(0,c).value.encode(‘GBK‘)+":" for i in range(1,sheet.nrows): lie[sheet.cell(i,0).value.encode(‘GBK‘)] = sheet.cell(i,c).value i = i+1 newlie = sorted(lie.iteritems(),key = lambda d:d[1],reverse = True) for i in range(0,len(newlie)): print newlie[i][0]+":"+"%.1f" %(newlie[i][1])+"分," , i = i+1 print "\n" start = time.time() if __name__ == ‘__main__‘: URL = r‘D:\python case\0.excel分数排序-2015.12.18\fenshu.xlsx‘ workbook = xlrd.open_workbook(URL,‘rb‘) sheet_name = workbook.sheet_names()[1] sheet = workbook.sheet_by_index(1) sheet = workbook.sheet_by_name(‘Sheet1‘) lie = {} print ‘-‘*20 for c in range(0,5): read_excel(c) c = time.time() - start print(‘程序运行耗时:%0.2f‘%(c))
时间: 2024-10-17 22:19:18