|
需求:根据分数列的数字,进行登记判断,并把等级写入C列。
- import xlrd
- from xlutils.copy import copy
- wb = xlrd.open_workbook('Chapter-3-17-1.xls')
- ws = wb.sheet_by_index(0)
- nwb = copy(wb)
- nws = nwb.get_sheet('分数表')
- nws.write(0,ws.ncols,'等级')
- for row_num in range(1,ws.nrows): #此处直接跳过首行
- if ws.cell_value(row_num,1)>90:
- nws.write(row_num,ws.ncols,'very good')
- elif ws.cell_value(row_num,1)>80:
- nws.write(row_num, ws.ncols, 'good')
- elif ws.cell_value(row_num,1)>60:
- nws.write(row_num, ws.ncols, 'ok')
- else:
- nws.write(row_num,ws.ncols, 'sorry')
- nwb.save('3.xls')
复制代码
|
|