python Excel操作

 1 """
 2 [['Id', 'Stu_id', 'C_name', 'Grade'], 
 3 (1, 801, '计算机', 98), 
 4 (2, 801, '中文', 49), 
 5 (3, 801, '英语', 80), 
 6 (4, 802, '计算机', 65), 
 7 (21, 1006, '英语', 45)]
 8 """
 9 
10 #excell操作
11 def wt_excell(temp):
12     # book = xlwt.Workbook()  # 新建一个excel
13     # sheet = book.add_sheet('sheet1')  # 加sheet页
14     # sheet.write(0, 0, '姓名')  # 行、列、写入的内容
15     # sheet.write(0, 1, '年龄')
16     # sheet.write(0, 2, '性别')
17     # book.save('stu.xls')  # 结尾一定要用.xls
18     workbook = xlwt.Workbook()
19     sheet = workbook.add_sheet('score', cell_overwrite_ok=True)
20     for x in range(len(temp)):
21         for i in range(len(temp[x])):
22             print(temp[x][i])
23             sheet.write(x, i, temp[x][i])
24     workbook.save('stu.xls')

猜你喜欢

转载自www.cnblogs.com/xinjing-jingxin/p/8997404.html