[Datatable] Export with formatting

I’ve added some formatting + conditional formatting to a DataTable.
I would like to allow the user to download the table (e.g. for offline work), but it would be much much better if I could add the formatting to the downloaded Excel.
Does anyone know if it’s even possible, and if so, how to achieve that ?
Thanks for any lead :wink:

I also have this question-- bump. Thanks.

Hello @mwrowe,

You could use an excel template that copy’s the formatting of the table. As long as they don’t have any custom formatting, it should be fine.

You might also be able to do this by using an excel writer. I know that you can format columns on exporting.

Thanks for your reply. I’m looking at the dcc.Download documentation, specifically the section for downloading dataframes as Excel. I am using openpyxl to enable this; the library can write formatted Excel files, but I don’t see any options in the dcc.Download component to access this functionality.

Seems like it might be possible to write my own function to create the formatted Excel, then download it using a button where the callback uses to dcc.to_file() function. But was hoping there might be built-in support for this that I had missed. Does this solution seem viable?

Thanks again.

Sure, what you can do is write to an io, format the excel file as you desire and then use dcc.send_bytes() with your formatted excel file. All to the dcc.Download.