解决 python用 xlsxwrite 向excel 中写入中文字符串变量 报错
时间:2015-09-23 12:00:16
收藏:0
阅读:1671
问题: UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe7 in position 7: ordinal not in range(128)
分析:在网上查找,原来python的str默认是ascii编码,和unicode编码冲突,所以无法 中文字符串变量写入excel。
解决:在代码中加入下面几行就可以了。
import sys reload(sys) sys.setdefaultencoding(‘utf8‘)
评论(0)