I already tried this one, but when I open the Excel spreadsheet, the whole Excel file is blank. Is there another way?
import xlsxwriter .... sheet.write(1, 27, "Französisch".decode('latin1'), bold)
Advertisement
Answer
Excel, and XlsxWriter, use either ASCII or UTF-8. To write a string like that in Python 2:
- Encode the file as UTF-8.
- Include the “coding” directive at the start of the file.
- Use u” to indicate a Unicode string.
Like this:
# _*_ coding: utf-8 import xlsxwriter workbook = xlsxwriter.Workbook('example.xlsx') worksheet = workbook.add_worksheet() worksheet.write('B3', u'Französisch') workbook.close()
In Python 3 you just need to encode the file as UTF-8.
See the Unicode examples in XlsxWriter docs.