import xlwt workbook=xlwt.Workbook(encoding="utf-8",style_compression=0) #创建workbook对象,style_compression表示是否压缩,不常用 worksheet=workbook.add_sheet('sheet1', cell_overwrite_ok=True) #cell_overwrite_ok=True, 可以覆盖原单元格中数据 worksheet.write(0,0,"hello") #写入数据,第一行参数“行”,第二个参数“列”,第三个参数内容 workbook.save('test.xls')
#写入99乘法表 import xlwt workbook=xlwt.Workbook(encoding="utf-8",style_compression=0) #创建workbook对象,style_compression表示是否压缩,不常用 worksheet=workbook.add_sheet('sheet1', cell_overwrite_ok=True) #cell_overwrite_ok=True, 可以覆盖原单元格中数据 for a in range(1,10): for b in range(1,a+1): # print("%s * %s = %s"%(a,b,a*b)) worksheet.write(a-1, b-1, "%s * %s = %s"%(a,b,a*b)) worksheet.col(0).width=20 workbook.save('test.xls')