python - xlwt insert table data horizontally
phpcn_u1582
phpcn_u1582 2017-05-18 10:50:46
0
2
732

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')
phpcn_u1582
phpcn_u1582

reply all(2)
滿天的星座

ws.write(index, r_num,r_value)

仅有的幸福
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')
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!