Apache POI如何将工作簿样式应用于所有数据透视表.我如何排除床单? [英] Apache POI how to apply Workbook Style to all Pivot Tables. how do i exclude sheets?
问题描述
所以我正在研究一个程序,该程序读取文本文件并将此数据写入excel工作簿中.写入数据后,我根据数据创建数据透视表.为了在枢纽分析表中获得样式,我设置了整个工作簿样式,这为什么只适用于具有枢纽分析表的表,而不适用于数据表.现在我想从工作簿样式中排除一张带有数据透视表的工作表.有没有一种方法可以排除一张纸或为需要的纸设置样式?
So i am working on a program which reads a text file and writes this data in an excel workbook. 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?
工作簿样式的代码:
wb.createDataFormat().putFormat((short) 0, "_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)");
数据透视表:
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. this question might also be more accurate on what i wanted to achieve
这篇关于Apache POI如何将工作簿样式应用于所有数据透视表.我如何排除床单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!