import xlrd,xlwt,os
book1=xlrd.open_workbook('E:/learn/python/day7/z_api/data/app_student.xls')
book2=xlwt.Workbook()#新建一个excel
sheet=book1.sheet_by_index(0)#打开sheet页
sheet2=book2.add_sheet('sheet1')#添假一个sheet页
title=sheet.row_values(0)#获取表头
title.append('是否毕业')
print(title)
tmp=1
for index,t in enumerate(title):
sheet2.write(0,index,t)
for row in range(1,sheet.nrows):#从第一行循环获取每行数据
line=sheet.row_values(row)#获取每一行数据
if '?' in str(line):#判断乱码是否在每一行
continue
else:
if line[5]=='天蝎座':
line.append('已毕业')
else:
line.append('未毕业')
for index,col in enumerate(line):
sheet2.write(tmp,index,col)
tmp+=1
os.remove('E:/learn/python/day7/z_api/data/app_student.xls')
book2.save('E:/learn/python/day7/z_api/data/app_student.xls')