如何使用Apache poi过滤xlsx数据透视表中的报表过滤器?

时间:2016-05-20 10:00:33

标签: java apache-poi xssf

Image link     我正在使用apache poi在excel中创建数据透视表,如下所示:

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

如何按特定项目过滤报告过滤器?

0 个答案:

没有答案