简体   繁体   English

Apache POI如何将工作簿样式应用于所有数据透视表。 我如何排除床单?

[英]Apache POI how to apply Workbook Style to all Pivot Tables. how do i exclude sheets?

So i am working on a program which reads a text file and writes this data in an excel workbook. 因此,我正在开发一个程序,该程序可读取文本文件并将此数据写入Excel工作簿中。 after the data is written i create pivot tables from the data. 写入数据后,我根据数据创建数据透视表。 to get style in the pivot table i've set the whole workbook style which somewhy only applys to the sheets with the pivot tables and not the data sheets. 为了在数据透视表中获得样式,我设置了整个工作簿样式,这为什么只适用于具有数据透视表的表而不是数据表。 now i want to exclude one sheet with pivot table from the workbook style. 现在我想从工作簿样式中排除一张带有数据透视表的表格。 is there a way to exclude one sheet or set the style for the sheets which need it? 有没有一种方法可以排除一张纸或为需要的纸设置样式?

code for workbook style: 工作簿样式的代码:

wb.createDataFormat().putFormat((short) 0, "_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)");

pivot table: 数据透视表:

CellReference cr = new CellReference("A1");
CellReference c1 = new CellReference(0, 0);
CellReference c2 = new CellReference(data.getPhysicalNumberOfRows() - 1, data.getRow(0).getLastCellNum() - 1);

AreaReference ar = new AreaReference(c1, c2);
XSSFPivotTable pivotTable = sheet.createPivotTable(ar, cr, data);

pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldArray(4).setAxis(STAxis.AXIS_COL);
pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldArray(4).addNewItems();
pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldArray(4).getItems().addNewItem()
        .setT(STItemType.DEFAULT);

pivotTable.getCTPivotTableDefinition().addNewColFields().addNewField().setX(4);

pivotTable.addRowLabel(10);
pivotTable.addRowLabel(11);
pivotTable.addRowLabel(1);
pivotTable.addColumnLabel(DataConsolidateFunction.COUNT, 0);

i already tried to set the style for the cells in the sheet but didn't work. 我已经尝试为工作表中的单元格设置样式,但是没有用。 any suggestions? 有什么建议么?

so i found an solution here: Apache Poi set data field style for pivot table . 所以我在这里找到了一个解决方案: Apache Poi为数据透视表设置了数据字段样式 this question might also be more accurate on what i wanted to achieve 这个问题在我想要实现的目标上也可能更准确

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM