当前位置:   article > 正文

python中对象不可迭代_Python - TypeError:'Cell'对象不可迭代(Python - TypeError: 'Cell' object is not iterable)...

cell' object is not iterable

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/865204?site
推荐阅读
相关标签
  

闽ICP备14008679号