问题
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