xlwt库主要是对excel进行操作,主要流程就是创建对象,创建工作表,写入数据,保存数据表。代码练习如下
'''
import xlwt
workbook = xlwt.Workbook(encoding="utf-8") #创建workbook对象
workSheet = workbook.add_sheet("sheet1") #创建工作表
workSheet.write(0,0,"hello") #写入数据,第一个参数行,第二个参数列,第三个参数内容
workbook.save("student.xls") #保存数据表
'''
import xlwt
workbook = xlwt.Workbook(encoding="utf-8")
worksheet = workbook.add_sheet("sheet2")
for a in range(0,9):
for b in range(0,a+1):
jieguo = (a+1)*(b+1)
worksheet.write(a+1,b+1,"%d*%d =%d"%(a+1,b+1,jieguo))
workbook.save("chengfa.xls")
标签:xlwt,sheet,encoding,python,jieguo,爬虫,数据表,workbook
From: https://www.cnblogs.com/he-cheng/p/17178890.html