python中对象不可迭代_Python - TypeError:'Cell'对象不可迭代(Python - TypeError: '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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值