We have a report which we can export as an Excel file, in that we have a column which contains Integers and “N/A”(string type), but when I go to Data >> Filter it gives me option to sort it from A to Z or Z to A in the first row(As we have Headers for each column which is of string type). But here I want to be Largest to smallest or vice versa.
Thing is that in the production environment we have the same code which we use in Dev environment but in Prod, we can sort it by Largest to smallest, but in the dev environment it gives option to sort only by A to Z or Z to A.
What can I do here to make dev environment same as prod. I have checked the whole code and both are giving same data types to the excel file.
I have tried replacing the “N/A” with a blank “”, then I am able to get the required result(Smallest to largest).
We are using the POI:Document ultility(https://github.com/wiggick/POIUtility)
to create a excel file in the ColdFusion.
Please suggest a way to do this in code itself because user of the excel don’t need it to do it manually from excel.
Without knowing more, I suspect it’s not a CF issue. Just the normal behavior of Excel when presented with columns containing mixed data types.
Unlike database tables, Excel allows a mix of numbers and strings to be stored in the same column. When you attempt to sort such a column, Excel has to “guess” what type of sorting options to present by scanning some of the cell values.
If the majority of values are numbers, Excel presents numeric sorting options: “Smallest to Largest” and “Largest to Smallest”
When the majority of values are strings, Excel presents text sorting options: “A to Z” or “Z to A”
I suspect what you’re seeing is caused by Prod and Dev using different data to populate the spreadsheets. As long as the cells are populated with a mix of both strings and numbers, I don’t think you can get around that.
A possible alternative is to only use numeric values when populating the spreadsheet, by substituting
0, for “N/A”. Then apply a custom cell format that displays “N/A” whenever the cell value is “0”. That would work as long as the value “0” isn’t already used for something else.
Example of Mixed Data Type Columns and Generated Sort Options