【发布时间】:2018-11-17 10:46:23
【问题描述】:
我在 Java 应用程序中工作以写入 excel。我正在使用 apache poi 库。我需要创建数据透视表。我可以使用下面的代码创建数据透视表并对列求和。
CellReference topLeft = new CellReference(0, 0);
CellReference bottomRight = new CellReference(10, 3);
AreaReference aref = new AreaReference(topLeft, bottomRight);
CellReference pos = new CellReference(0, 0);
XSSFSheet pivotSheet = workbook.createSheet("PivotSheet");
XSSFPivotTable pivotTable = pivotSheet.createPivotTable(aref,pos,dataSheet)
pivotOrgWiseSheet.setDisplayGridlines(true);
pivotTable.addRowLabel(0);
pivotTable.addRowLabel(1);
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 2, "Sum of column3");
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 3, "Sum of column4");
但我不确定为什么关键字“values”出现在第二列标题中,并且是否可以将值“Row Label”更改为自定义文本,如“Category”
我想要类似下面的东西。
我不确定如何删除关键字“Values”,但我猜想将标题更改为自定义字符串,我们必须获取值并将其设置出来?
【问题讨论】:
标签: java excel apache-poi pivot-table