There is data:
[(1,),(2,),(3,)],[('a',),('b',),('c',)], [('e',),('f',),('g',)] respectively represent the values of three different columns.
The requirement is: write table records horizontally:
My program is as follows. It can only implement sequence insertion. I don’t know how to modify the insertion order. Please give me some guidance.
import xlwt
wb = xlwt.Workbook(encoding='utf-8')
ws = wb.add_sheet('Sheet1', cell_overwrite_ok=True)
data = (
[(1,),(2,),(3,)],
[('a',),('b',),('c',)],
[('e',),('f',),('g',)],
)
for index, value in enumerate(data):
for r_num, r_value in enumerate(value):
ws.write(r_num, index,r_value[0])
wb.save('test.xls')
仅有的幸福2017-05-18 10:52:46
import xlwt
wb = xlwt.Workbook(encoding='utf-8')
ws = wb.add_sheet('Sheet1', cell_overwrite_ok=True)
data_old = (
[(1,),(2,),(3,)],
[('a',),('b',),('c',)],
[('e',),('f',),('g',)],
)
data = [i for i in map(list,zip(*data_old))]
col = len(data)
row = len(data[0])
for r_row in range(row):
for r_col in range(col):
ws.write(r_row,r_col,data[r_row][r_col][0])
wb.save('test.xls')