为了账号安全,请及时绑定邮箱和手机立即绑定

python xlwt 向excel中写数据,excel文档打不开

python xlwt 向excel中写数据,excel文档打不开

阿波罗的战车 2018-07-16 07:17:42
收藏(0)运行代码:import csvimport xlwtworkbook = xlwt.Workbook()sheet2 = workbook.add_sheet("Sheet 2", cell_overwrite_ok=True)file = open(r'D:\label.csv')lines = csv.reader(file)r = 0for line in lines:    col = 0    for c in line:        sheet2.row(r).write(col,c, style=xlwt.Style.default_style)        #print(c,end=' ')        col += 1    r += 1    sheet2.flush_row_data()    file.close()   workbook.save("csv2excel.xlsx")
查看完整描述

1 回答

?
明月笑刀无情

TA贡献1828条经验 获得超4个赞

文件扩展名要以2003 为准。 你把保存文件名扩展名改成 xls  (csv2excel.xls)

查看完整回答
1 反对 回复 2018-07-18
  • 1 回答
  • 0 关注
  • 8208 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信