You need to create an Excel pivot table from Java in the format “Classic Pivot Table Layout”, that is, in the form of Excel 2003.

In Apache POI - I did not find this functionality, SmartXLS - paid.

Are there any libraries to create?

1 answer 1

Try this:

public static void main(String[] args) throws FileNotFoundException, IOException, InvalidFormatException { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet) wb.createSheet(); //Create some data to build the pivot table on setCellData(sheet); XSSFPivotTable pivotTable = sheet.createPivotTable(new AreaReference("A1:D4"), new CellReference("H5")); //Configure the pivot table //Use first column as row label pivotTable.addRowLabel(0); //Sum up the second column pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1); //Set the third column as filter pivotTable.addColumnLabel(DataConsolidateFunction.AVERAGE, 2); //Add filter on forth column pivotTable.addReportFilter(3); FileOutputStream fileOut = new FileOutputStream("ooxml-pivottable.xlsx"); wb.write(fileOut); fileOut.close(); } 

In Apache there is an example even.

A source.

  • So I tried, and even started the example you specified, but the formation takes place in summary 2007, that is, with the “Classic layout pivot table” ticked off in the properties of the pivot table, I think the problem is that the formation takes place through the library for 2007 Excel, in the HSSF class , there is no "createPivotTable" method. - ezhov_da