python exlcel 操作例子


book = xlwt.Workbook()
sheet = book.add_sheet("sheet1")
title = ["id","name","sex","city"]
students = [
[1,"a","男","北京"],
[2,"b,"男","北京"],
[3,"c","女","深圳"],
[4,"d","女","北京"],
]
students.insert(0,title)
for row,student in enumerate(students):
for col,value in enumerate(student):
sheet.write(row,col,value)


book.save("test.xls")

 

上一篇:遍历列表、元组或字符串的函数enumerate


下一篇:Python中的迭代(Iteration)