如何使用Apache POI的XSSF创建一个数据透视表?

huangapple go评论58阅读模式
英文:

How to create a pivot table with xssf using apache poi?

问题

我需要按以下方式设置数据透视表:

如何使用Apache POI的XSSF创建一个数据透视表?

我需要的输出如上所示,但我得到的输出如下所示:

如何使用Apache POI的XSSF创建一个数据透视表?

我已经按以下方式编写了代码:

pivotTable.addReportFilter(12);
pivotTable.addReportFilter(13);
pivotTable.addRowLabel(11);
pivotTable.addDataColumn(15, true);
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 15);

如何按所需方式获取列过滤器?

英文:

I have a requirement where i need the pivot table in following manner:

如何使用Apache POI的XSSF创建一个数据透视表?

I needed the output in the above manner, but I'm getting in the following manner:

如何使用Apache POI的XSSF创建一个数据透视表?

I have written the code in following manner:

pivotTable.addReportFilter( 12 );
pivotTable.addReportFilter( 13 );
pivotTable.addRowLabel( 11 );
pivotTable.addDataColumn( 15, true );
pivotTable.addColumnLabel( DataConsolidateFunction.SUM, 15 );

How to get the column filter as required??

答案1

得分: 0

我已将apache-poi从3.14版本升级到4.1.0版本,其中4.1.x版本提供了addColLabel(columnIndex)方法。使用addColLabel(columnIndex)方法允许选择特定列作为数据透视表创建的列字段。

代码:

pivotTable.addReportFilter(12);
pivotTable.addReportFilter(13);
pivotTable.addRowLabel(11);
pivotTable.addColLabel(0);
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 15);
英文:

I have updated the apache-poi from 3.14 to 4.1.0, where 4.1.x version provides the method addColLabel(columnIndex). Using addColLabel(columnIndex) allows to select particular column as column fields for the pivot table creation.

Code:

            pivotTable.addReportFilter( 12 );
			pivotTable.addReportFilter( 13 );
			pivotTable.addRowLabel( 11 );
			pivotTable.addColLabel( 0 );
			pivotTable.addColumnLabel( DataConsolidateFunction.SUM, 15 );

huangapple
  • 本文由 发表于 2020年8月4日 17:24:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63243850.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定