带有xlwt的UnicodeDecodeError

时间:2013-12-06 17:28:04

标签: python python-2.7 xlwt

我正在使用python和xlwt并遇到问题

我的代码:

tickets = cursor.fetchall ()
largo = len(tickets)
cursor.close ()
conn.close ()

row = 4
for t in tickets:

  hoja.write(row, 1, t[0])
  hoja.write(row, 2, epoch2fecha(t[1]))
  hoja.write(row, 3, epoch2fecha(t[12]))
  hoja.write(row, 6, t[10])
  hoja.write(row, 7, t[9])
  hoja.write(row, 8, t[6])
  hoja.write(row, 9, t[3])
  row += 1
  if(row == largo+1):
     break
libro.save('Informe.xls')

错误:

libro.save('informe.xlsx')
File "build/bdist.linux-x86_64/egg/xlwt/Workbook.py", line 662, in save
File "build/bdist.linux-x86_64/egg/xlwt/Workbook.py", line 637, in get_biff_data
File "build/bdist.linux-x86_64/egg/xlwt/Workbook.py", line 599, in __sst_rec
File "build/bdist.linux-x86_64/egg/xlwt/BIFFRecords.py", line 76, in get_biff_record
File "build/bdist.linux-x86_64/egg/xlwt/BIFFRecords.py", line 91, in _add_to_sst
File "build/bdist.linux-x86_64/egg/xlwt/UnicodeUtils.py", line 50, in upack2
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf3 in position 6: ordinal not in range(128)

1 个答案:

答案 0 :(得分:9)

您是否尝试过将latin-1编码为工作簿?

from xlwt import Workbook

hoja = Workbook(encoding='latin-1')