In an Excel 97-2003 XLS file, each text fragment is encoded in latin1 , if possible, otherwise UTF-16LE , with a flag to indicate which one. For this, xlwt nees a unicode object. If the caller sends the str object, xlwt will try to decode it using the encoding specified in the Workbook () call (the default is ascii ).
It works; try running the following short script and open the resulting file with Excel.
import xlwt wb = xlwt.Workbook(encoding="UTF-8") uc = u"".join(unichr(0x0410 + i) for i in xrange(32))
The fact that you are getting a coding error, not a decoding error, indicates a possible problem in the input of your script file. Please put the shortest script that causes the error you receive. The script should contain something like print repr(your_utf8_text) just before the error output so that we can see exactly what the text data is. Please provide a complete error message and full trace, as well as the contents ( print repr(contents) ) of your very short input file.
source share