Python XLWT: Write a list into a cell

北战南征 提交于 2019-12-10 19:10:54

问题


I am trying to write a list into a cell using Python XLWT. Is this possible?

I am currently getting an error:

Exception: Unexpected data type <type 'list'>

The code:

    for x in result:
        sheet1.write(row2,0,x[0])
        sheet1.write(row2,1,x[1])

x[1] will be a list.

Thanks!


回答1:


Try converting it to a string first:

for x in result:
    sheet1.write(row2,0,str(x[0]))
    sheet1.write(row2,1,str(x[1]))


来源:https://stackoverflow.com/questions/7747997/python-xlwt-write-a-list-into-a-cell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!