Rumah > Soal Jawab > teks badan
Terdapat data:
[(1,),(2,),(3,)],[('a',),('b',),('c',)],[('e ',),('f',),('g',)] masing-masing mewakili nilai tiga lajur berbeza.
Keperluan ialah: tulis rekod jadual secara mendatar:
Program saya adalah seperti berikut Ia hanya boleh melaksanakan sisipan urutan. Saya tidak tahu cara mengubah suai susunan sisipan.
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')