2 回答
TA贡献1752条经验 获得超4个赞
1 2 3 4 5 6 7 8 | import xlwt f = xlwt.Workbook() #创建工作簿 sheet1 = f.add_sheet(u'sheet1',cell_overwrite_ok=True) #创建sheet l_=[1,2,3,4,5] for i in range(len(l_)): sheet1.write(0,i,i)#表格的第一行开始写。第一列,第二列。。。。 #sheet1.write(0,0,start_date,set_style('Times New Roman',220,True)) f.save('text.xls')#保存文件 |
TA贡献1805条经验 获得超9个赞
文件存储是按照每个子列表为一行的,所以在写文件时只需要将[10,'haha',0.1]换成[[10],['haha'],[0.1]]。所以只要将mywrite.writerow(i)改为mywrite.writerow([i])。
1 2 3 4 5 6 7 8 9 | import csv def storFile(data,fileName):
with open(fileName,'w',newline ='') as f: mywrite = csv.writer(f) for i in data: mywrite.writerow([i]) data = [10,'haha',0.1] storFile(data,"haha.csv") |
添加回答
举报