3

Image link I am using apache poi to create pivot table in excel as below :

FileInputStream fis = new FileInputStream(new File("Input/Book2.xlsx"));
    XSSFWorkbook workbook = new XSSFWorkbook(fis);

XSSFSheet spreadsheet = workbook.getSheetAt(2);

XSSFSheet sheet = workbook.getSheetAt(3);
AreaReference a=new AreaReference("A1:D4");
/* Define the starting Cell Reference for the Pivot Table */
CellReference b=new CellReference("C2");
/* Create the Pivot Table */
XSSFPivotTable pivotTable = sheet.createPivotTable(a,b,spreadsheet);
/* First Create Report Filter - We want to filter Pivot Table by Student Name */

pivotTable.addReportFilter(0);

 /* Second - Row Labels - Once a student is filtered all subjects to be displayed in pivot table */
pivotTable.addRowLabel(1);
/* Define Column Label with Function, Sum of the marks obtained */
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 2);     
//pivotTable.getCTPivotTableDefinition().setMultipleFieldFilters(true);

/* Write output to file */ 
FileOutputStream output_file = new FileOutputStream(new File("POI_XLS_Pivot_Example.xlsx")); //create XLSX file
workbook.write(output_file);//write excel document to output stream
output_file.close(); //close the file

How can I filter report filter by particular item?

Sowmya
  • 453
  • 1
  • 5
  • 18

0 Answers0