apache POI pivot table sort the column which shows months in chronological order

Viewed 40

I am creating the pivot table using apache POI and need to show month based columns in pivot table in chronological order. I found the below solution but i'm getting the exception.

  XSSFWorkbook workbook = new XSSFWorkbook();
//logic to get data in sheet and createPivot table.
//XSSFSheet dataSheet = ..;
 //XSSFPivotTable pivotTable1 = sheet.createPivotTable(ar, cr1, dataSheet);
   int indexOfSortColumn = 1;
    pivotTable1.getCTPivotTableDefinition()
            .getPivotFields()
            .getPivotFieldArray(indexOfSortColumn)
            .setSortType(STFieldSortType.ASCENDING);

build.gradle:

//implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '4.1.2'
implementation group: 'org.apache.poi', name: 'ooxml-schemas', version: '1.1'

To use the above STFieldSortType.Ascending , it required ooxml-schemas so commented the existing one in build.gradle and added the other as shown above.

Exception :

java.lang.NoSuchMethodError: 'org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontFamily org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont.addNewFamily()'

Any inputs on how to sort columns which shows months( in chronological order starting from Jan to December.)

---EDIT-- Exception is gone after working with different version of ooxml-schemas but the sort by column is yet not working when used the above code.

below are the dependencies :

implementation group: 'org.apache.poi', name: 'poi-ooxml-full', version: '5.2.2'
implementation group: 'org.apache.poi', name: 'ooxml-schemas', version: '1.3'
0 Answers
Related