i have file containing data below
a,b,c,d e,f,g,h i,j,k,l
i trying write excel file in 4 columns using xlwt in python. want in excel need create multiple sheets in same file. there lot of examples on how write 2 columns looping, couldn't find example of writing multiple columns. can body tell me how done ?
the following should looking for:
import xlwt data1 = [["a1", "b1", "c1", "d1"], ["e1", "f1", "g1", "h1"], ["i1", "j1", "k1", "l1"]] data2 = [["a2", "b2", "c2", "d2"], ["e2", "f2", "g2", "h2"], ["i2", "j2", "k2", "l2"]] data3 = [["a3", "b3", "c3", "d3"], ["e3", "f3", "g3", "h3"], ["i3", "j3", "k3", "l3"]] sheets = ["sheet 1", "sheet 2", "sheet 3"] wb = xlwt.workbook() sheet, data in zip(sheets, [data1, data2, data3]): ws = wb.add_sheet(sheet) row, row_value in enumerate(data): col, col_value in enumerate(row_value): ws.write(row, col, col_value) wb.save('output.xls')
this give excel file looking like:
Comments
Post a Comment