xlwt模块-保存xls unicode错误 [英] xlwt module - saving xls unicode error
本文介绍了xlwt模块-保存xls unicode错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用xlwt模块保存一些文本,创建新的xls文档并在那里保存文本。到目前为止,它一直很好,直到遇到unicode文本为止:例如简单的字符串'80°'。
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°'.
当我调用 book.save('simple.xls')
时得到 UnicodeDecodeError:'ascii'编解码器无法解码字节0xc2
。有什么办法可以避免这种情况?
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?
推荐答案
写一个普通字符串,写一个Unicode字符串。例如,代替
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.)
这篇关于xlwt模块-保存xls unicode错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文