import xlrd import datetime import uuid import os def process_cell(table,i,j): _temp=table.cell(i,j) if _temp.ctype==1: return _temp.value if _temp.ctype==2: return str(int(_temp.value)) #raise "Error xls!" def processxls(FILE): BASE_DIR = os.path.dirname(os.path.dirname(__file__)) xlsname = os.path.join(BASE_DIR, 'uploads', '%s.xls' % str(uuid.uuid4())) destination = open(xlsname,'wb') for chunk in FILE.chunks(): destination.write(chunk) destination.close() data = xlrd.open_workbook(xlsname) table = data.sheet_by_index(0) head = table.row_values(0) assert len(head)==2 rets=[] for i in range(table.nrows-1): col = table.row_values(i+1) classid=str(int(col[0])) name=process_cell(table,i+1,1) rets.append((classid,name)) return rets