xlwt module - saving xls unicode error

心不动则不痛 提交于 2019-12-13 01:23:53

问题


I'm trying to save some text with xlwt module, creating new xls document and saving text there.So far it worked great, until I came across unicode text: for example simple string '80°'.

When I call book.save('simple.xls') I get UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2.Is there any way I can avoid that?


回答1:


Instead of writing a regular string, write a Unicode string. For example, instead of

ws.write(r, c, '80°')

do

ws.write(r, c, '80°'.decode('cp1252'))

(Of course, pick the appropriate encoding for your data.)



来源:https://stackoverflow.com/questions/15148729/xlwt-module-saving-xls-unicode-error

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