访问"显示详细信息/隐藏详细信息" Excel中用于折叠数据透视表字段的选项

时间:2015-11-12 12:49:02

标签: java excel

我创建了一个实用程序来创建数据透视表但无法折叠它。这是我的代码:

 /* Read the input file that contains the data to pivot */
 FileInputStream input_document = new FileInputStream(new File("D:\\StateCity.xlsx"));    

 /* Create a POI XSSFWorkbook Object from the input file */
 XSSFWorkbook my_xlsx_workbook = new XSSFWorkbook(input_document); 

 /* Read Data to be Pivoted - we have only one worksheet */
 XSSFSheet sheet = my_xlsx_workbook.getSheetAt(1); 

 /* Get the reference for Pivot Data */
 AreaReference a=new AreaReference("A1:D11");

 /* Find out where the Pivot Table needs to be placed */
 CellReference b=new CellReference("A2");

 XSSFSheet license_usage = my_xlsx_workbook.getSheet("sheet2");
 XSSFSheet sheet1 = (XSSFSheet)  my_xlsx_workbook.createSheet("license_pivot_table");
 /* Create Pivot Table */
 XSSFPivotTable pivotTable = sheet1.createPivotTable(a,b,license_usage);


 pivotTable.addRowLabel(0);
 pivotTable.addRowLabel(1);
 pivotTable.addRowLabel(2);
 pivotTable.addRowLabel(3);

 for(CTPivotField ctPivotField:pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldList()){
     ctPivotField.setAutoShow(false);
     ctPivotField.setOutline(false);
     ctPivotField.setCompact(false);


     ctPivotField.setSubtotalTop(false);
     ctPivotField.setSubtotalCaption("");
 }
            pivotTable.getCTPivotTableDefinition().setRowGrandTotals(false);
 CTPivotTableDefinition ctPivotTableDefinition = pivotTable.getCTPivotTableDefinition();
 CTPivotTableStyle ctPivotTableStyle = ctPivotTableDefinition.getPivotTableStyleInfo();
 ctPivotTableStyle.setName("PivotStyleMedium3");

 /* Write Pivot Table to File */
 FileOutputStream output_file = new FileOutputStream(new File("D:\\POI_XLS_Pivot_ExampleTest.xlsx"));
 my_xlsx_workbook.write(output_file);

 input_document.close(); 

我不想使用Aspose.Cells,因为它是一种许可产品。

0 个答案:

没有答案