#!/usr/bin/env python
# _*_ coding:utf-8 _*_
#操作Excel表格
import xlwt
#创建表格
book = xlwt.Workbook()#创建一个Excel
#创建sheet页
sheet = book.add_sheet('sheet1',cell_overwrite_ok=True)#创建一个sheet页
#表格中单元格写入数据
sheet.write(0,0,"姓名")
sheet.write(0,1,"年龄")
sheet.write(0,2,"身高")
sheet.write(1,0,"王胜利")
sheet.write(1,1,"38")
sheet.write(1,2,"150cm")
#保存表格
book.save('王胜利.xls')#后缀必须是xls
title = ['姓名','班级','住址','手机号']
data = [
['王胜利','巨蟹座','中南海',110],
['贾宝玉', '巨蟹座', '紫禁城', 119],
['老孙', '巨蟹座', '花果山', 114],
['光远', '巨蟹座', '天空', 120]
]
i = 0#控制列
for j in title:
sheet.write(0,i,j)
i+=1#每次循环的时候加1
#列表或者元组写入表格方法
for d in range(len(data)):
for j in range(len(data[d])):
sheet.write(d+1,j,data[d][j])
book.save('stu.xls')