user6753358
user6753358

Reputation: 59

Data displayed wrong when exported to excel

So I have this code:

import itertools
import xlsxwriter
from pprint import pprint

inputdata = [
    ['900x200', '200x500', '232x232'],
    ['242423', '232d2s', '2sdad'],
    ['AA', 'BB'],
]
result = list(itertools.product(*inputdata))
pprint(result)

workbook = xlsxwriter.Workbook('Documents/files/arrays.xlsx')
worksheet = workbook.add_worksheet()

row = 0

for col, data in enumerate(result):
    worksheet.write_column(row, col, data)

workbook.close()

First part generates combinations then it's saved to a excel file.

My issue is that items are displayed like this:
= = = = = = = =
= = = = = = = =
= = = = = = = =

And I want them to be like:
= = =
= = =
= = =
= = =
= = =
= = =
= = =

Basically just "rotate" as the data doesn't make much sense currently.

Upvotes: 0

Views: 49

Answers (1)

animalknox
animalknox

Reputation: 148

You're just not using the write function for the output you want. Change worksheet.write_column(row, col, data) to worksheet.write_row(row, col, data)

Basically your new script should be:

import itertools
import xlsxwriter
from pprint import pprint

inputdata = [
    ['900x200', '200x500', '232x232'],
    ['242423', '232d2s', '2sdad'],
    ['AA', 'BB'],
]
result = list(itertools.product(*inputdata))
pprint(result)

workbook = xlsxwriter.Workbook('arrays.xlsx')
worksheet = workbook.add_worksheet()

col = 0

for row, data in enumerate(result):
    worksheet.write_row(row, col, data)

workbook.close()

This produces the output you want

Upvotes: 4

Related Questions