我正在通过 python 访问 Excel 来调整单元格的某些编码。到目前为止我的代码:
from xlrd import *
from xlwt import *
wb = open_workbook('a.xls')
s = wb.sheets()[0]
for row in range(s.nrows):
e = s.cell(row,9).value
r = s.cell(row,11).value
print e,' ',r.decode('cp1251')
运行此代码时,我收到此错误:
Traceback (most recent call last):
File "C:\Users\pem\workspace\a\src\a.py", line 17, in <module>
print e,' ',r.decode('cp1251')
File "C:\Python27\lib\encodings\cp1251.py", line 15, in decode
return codecs.charmap_decode(input,errors,decoding_table)
File "C:\Python27\lib\encodings\cp1251.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character u'\xf6' in position 23: character maps to <undefined>
我知道e是英文文本,r是 1251 编码的俄文翻译。