【问题标题】:Apache POI how to apply Workbook Style to all Pivot Tables. how do i exclude sheets?Apache POI 如何将工作簿样式应用于所有数据透视表。我如何排除工作表?
【发布时间】:2016-11-03 09:55:58
【问题描述】:

所以我正在开发一个读取文本文件并将这些数据写入 Excel 工作簿的程序。写入数据后,我从数据创建数据透视表。为了在数据透视表中获得样式,我设置了整个工作簿样式,它为什么只适用于带有数据透视表的工作表而不是数据表。现在我想从工作簿样式中排除一张带有数据透视表的工作表。有没有办法排除一张表或为需要它的表设置样式?

工作簿样式代码:

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);

我已经尝试为工作表中的单元格设置样式,但没有成功。有什么建议么?

【问题讨论】:

    标签: java apache-poi pivot-table


    【解决方案1】:

    所以我在这里找到了解决方案:Apache Poi set data field style for pivot table。这个问题也可能更准确地说明我想要实现的目标

    【讨论】:

      猜你喜欢
      • 2018-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      相关资源
      最近更新 更多