"Export to Excel" results in incorrectly formatted cells

Hey everyone, I have an ag-grid set up in my app to display data in a table, with an “export to excel button” which downloads a .csv version of the data displayed in the grid. The data in the grid is in the form of percentages, which Excel seems to pick up when opening the .csv file; however, if there are negative numbers in the data, these numbers show up as text/strings in excel, not as numbers/percentages.

For example, here’s a snippet of the data in my app:

And here’s how it’s showing up in Excel. Note the “General” format in the top right when I select a cell with a negative number:

Screenshot 2024-05-06 at 9.25.12 AM

And note the correct “Percentage” format in the top right when I select a cell with a positive number:

It seems like the negative sign is causing Excel to think it’s a string.

Has anyone run into this issue before? This data is from a pandas dataframe so I’ve tried using astype and to_numeric to format the pandas data itself. I’ve also tried using excelStyles in dashGridOptions, with no luck (it doesn’t seem to pick up any formatting that I put excelStyles).

Any help would be much appreciated!

Hello @nateadams

Welcome to the community!

Have you tried exporting the df to excel via a callback method? This will give you more control over how the file is exported.

Check out this post:

1 Like