简体   繁体   中英

Using xlsxwriter to Align Left a Row

xlsxwriter has been pretty powerful and almost everything I want is working, but the following attempt to align left a single row doesn't seem to work.

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)

See the XlsxWriter docs for Formatting of the Dataframe headers :

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM