import xlwt book = xlwt.Workbook() #创建Excel sheet = book.add_sheet('sheet1') #创建sheet页 data = [ ["A",99,100,98.5], ["B",90,30.5,95], ["C",67.5,49.6,88] ] title = ['姓名','语文成绩','数学成绩','英语成绩'] #把表头名称放入list里面 #循环把表头写入 row = 0 for t in title: sheet.write(0,row,t) row+=1 row = 1 # 从表格的第二行开始写入数据 # 一行一行的写,一行对应的所有列 for d in data: #控制行 col = 0 for one in d:#控制每一列 sheet.write(row,col,one) #rou代表列,col代表行,one写入值 col+=1 row+=1 book.save('student2.xls')