I am using the licensed version of Aspose-Cells 18.10 with JAVA 1.8 for one of the projects in my organization. One of the requirements I have is to sort data fields in a pivot table.
I went through this thread and it was mentioned that this issue has been fixed in Aspose-Cells 19.11. I switched to 19.11 but the issue is still there.
Please find the sample code and input file attached. I am trying to sort the pivot table based on the 3rd data field named ‘Sum of TOTAL PRICE’ (with index 2) in descending order. I was easily able to achieve this using Excel. I have also attached a copy of the expected output sorted using Excel.Sorting data samples.zip (30.3 KB)
Please provide a fix for this since it has been a blocker for a really long time.
String pathToInputFile = "Enter file path here"; String pathToSaveFile = "Enter save location here"; Workbook workbook = new Workbook(pathToInputFile ); Worksheet worksheet = workbook.getWorksheets().get( "PivotTable" ); PivotTable tbl = worksheet.getPivotTables().get( 0 ); tbl.calculateData(); PivotField sortField = tbl.getDataFields().get( 2 ); sortField.setAutoSort( true ); sortField.setAscendSort( false ); sortField.setAutoSortField( -1 ); tbl.refreshData(); workbook.save( pathToSaveFile );