I already tried this one, but when I open the Excel spreadsheet, the whole Excel file is blank. Is there another way?
JavaScript
x
5
1
import xlsxwriter
2
3
.
4
sheet.write(1, 27, "Französisch".decode('latin1'), bold)
5
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:
JavaScript
1
11
11
1
# _*_ coding: utf-8
2
3
import xlsxwriter
4
5
workbook = xlsxwriter.Workbook('example.xlsx')
6
worksheet = workbook.add_worksheet()
7
8
worksheet.write('B3', u'Französisch')
9
10
workbook.close()
11
In Python 3 you just need to encode the file as UTF-8.
See the Unicode examples in XlsxWriter docs.