import xlwt#写excel用的是xlwt模块
http://www.nnzhp.cn/archives/142 #博客目录
book=xlwt.Workbook()#新建一个excel
sheet=book.add_sheet('sheet1')#添加一个sheet页
print(dir(sheet))#查看sheet有啥方法
sheet.write(0,0,'姓名')
sheet.write(0,1,'性别')
sheet.write(0,2,'年龄')
book.save('stu.xls')# 微软的office不能用xlsx结尾的,wps随意
stus = [
[ '姓名','年龄','性别','分数'],
['mary', 20, '女', 89.9],
['lucy', 50, '女', 100],
['CiCi', 10, '女', 89.9],
['Tom', 25, '男', 88]]
rows=0# 控制行
for stu in stus:
new_colums = 0; # 控制列
for s in stu:
sheet.write(rows,new_colums,s)
new_colums=new_colums+1
rows=rows+1
book.save('new_stu1.xls')