1

What I'm trying to do is basically to write a new excel file from the data that I get from a list. The contents of the list is the row contents that I'm trying to write in the new excel file using the xlsxwriter (specifically xlsx because I'm using xlsx). Assuming that I have the code snippet below, it yields me the error :

TypeError: 'Cell' object is not iterable

The whole stacktrace points this out during the write event.

Traceback (most recent call last):
File "Desktop/excel-copy.py", line 33, in <module>
    sheet.write_row(row_index, col_index, cell_value)
  File "/usr/local/lib/python2.7/dist-packages/xlsxwriter/worksheet.py", line 64, in cell_wrapper
    return method(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/xlsxwriter/worksheet.py", line 989, in write_row
    for token in data:
TypeError: 'Cell' object is not iterable


import xlrd
import xlsxwriter

new_workbook = xlsxwriter.Workbook()
sheet = new_workbook.add_worksheet('stops')

#copy all row and column contents to new worksheet
for row_index, row in enumerate(ordered_list_stops):
    for col_index, cell_value in enumerate(row):
        print("WRITING: " + str(cell_value) + "AT " + str(row_index)+ " " + str(col_index))
        sheet.write_row(row_index, col_index, cell_value)

new_workbook.save('output.xlsx')

I can't quite point out whether cell_value is the cause. I tried printing it out and this is the result:

WRITING: text:u'4977'AT 0 0

1 Answer 1

2

The problem is that write_row takes a list (or other iterable) of values, and you're passing a single Cell object (cell_value) instead.

You either want to use sheet.write(row_index, col_index, cell_value), or skip the inner for loop and use sheet.write_row(row_index, 0, row)

Sign up to request clarification or add additional context in comments.

1 Comment

Indeed! Thanks! I just have another error but I'll be posting that in a separate question I guess :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.