我已经尝试过这个,但是当我打开Excel电子表格时,整个Excel文件都是空白的。还有另一种方式吗?
import xlsxwriter
....
sheet.write(1, 27, "Französisch".decode('latin1'), bold)
答案 0 :(得分:1)
Excel和XlsxWriter使用ASCII或UTF-8。在Python 2中编写类似的字符串:
像这样:
# _*_ coding: utf-8
import xlsxwriter
workbook = xlsxwriter.Workbook('example.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('B3', u'Französisch')
workbook.close()
在Python 3中,您只需要将文件编码为UTF-8。
答案 1 :(得分:0)
我已经看到你的问题进行了一些研究并找到了一个例子。
import xlsxwriter
# Create an new Excel file and add a worksheet.
workbook = xlsxwriter.Workbook('demo.xlsx')
worksheet = workbook.add_worksheet()
# Widen the first column to make the text clearer.
worksheet.set_column('A:A', 20)
# Add a bold format to use to highlight cells.
bold = workbook.add_format({'bold': True})
# Write some simple text.
worksheet.write('A1', 'Hallo')
# Text with formatting.
worksheet.write('A2', 'Welt', bold)
# Write some numbers, with row/column notation.
worksheet.write(2, 0, 123)
worksheet.write(3, 0, 123.456)
# Insert an image.
worksheet.insert_image('B5', 'logo.png')
workbook.close()
应该工作;) 有关详细信息,请访问:XlsxWriter