使用 xlsxwriter 左对齐一行
Using xlsxwriter to Align Left a Row
xlsxwriter 非常强大,几乎我想要的一切都能正常工作,但以下尝试左对齐一行似乎不起作用。
stats = DataFrame(...)
xl_writer = ExcelWriter(r'U:\temp\test.xlsx')
stats.to_excel(xl_writer, 'Stats')
workbook = xl_writer.book
format_header = workbook.add_format({'align': 'left'})
stats_sheet = xl_writer.sheets['Stats']
stats_sheet.set_row(0, None, format_header)
请参阅 Formatting of the Dataframe headers 的 XlsxWriter 文档:
Pandas writes the dataframe header with a default cell format. Since it is a cell format it cannot be overridden using set_row()
. If you wish to use your own format for the headings then the best approach is to turn off the automatic header from Pandas and write your own. For example...
xlsxwriter 非常强大,几乎我想要的一切都能正常工作,但以下尝试左对齐一行似乎不起作用。
stats = DataFrame(...)
xl_writer = ExcelWriter(r'U:\temp\test.xlsx')
stats.to_excel(xl_writer, 'Stats')
workbook = xl_writer.book
format_header = workbook.add_format({'align': 'left'})
stats_sheet = xl_writer.sheets['Stats']
stats_sheet.set_row(0, None, format_header)
请参阅 Formatting of the Dataframe headers 的 XlsxWriter 文档:
Pandas writes the dataframe header with a default cell format. Since it is a cell format it cannot be overridden using
set_row()
. If you wish to use your own format for the headings then the best approach is to turn off the automatic header from Pandas and write your own. For example...