Apache的POI:Excel数据透视表 - 行标签 [英] Apache POI : Excel Pivot Table - Row Label
问题描述
我有一个要求,以创建一个Excel工作表中的JAVA如下:
I have a requirement to create a excel sheet in JAVA as below :
我不能够创建并排(菜单和子菜单过滤器)。多列侧行标签
I am not able to create a row label with multiple columns side by side ( menus and submenus filter ).
而不是显示在不同的列子菜单,其菜单栏下的到来。
Instead of displaying the submenu in different column, its coming under the menu column.
下面是我写的一张code的:
Below is the piece of code which i have written :
XSSFSheet sheet = my_xlsx_workbook.getSheetAt(0);
AreaReference a=new AreaReference("A1:G7");
CellReference b=new CellReference("I5");
XSSFPivotTable pivotTable = sheet.createPivotTable(a,b);
pivotTable.addReportFilter(0);
pivotTable.addReportFilter(1);
pivotTable.addRowLabel(2);
pivotTable.addRowLabel(3);
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 4, "Sum");
但它得到错误显示如下:
But its getting wrongly displayed as below :
有人能帮帮我吗?
推荐答案
由于格式是XML,很容易检查所需要的。解压邮编
XLSX,并期待在 /xl/pivotTables/pivotTable1.xml
。
Since the format is XML it is easy to check what is needed. Unpack the Zip
xlsx and look in the /xl/pivotTables/pivotTable1.xml
.
然后:<一href=\"https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFPivotTable.html#getCTPivotTableDefinition%28%29\" rel=\"nofollow\">https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFPivotTable.html#getCTPivotTableDefinition%28%29和<一个href=\"http://grep$c$c.com/file/repo1.maven.org/maven2/org.apache.poi/ooxml-schemas/1.1/org/openxmlformats/schemas/s$p$padsheetml/x2006/main/CTPivotTableDefinition.java\" rel=\"nofollow\">http://grep$c$c.com/file/repo1.maven.org/maven2/org.apache.poi/ooxml-schemas/1.1/org/openxmlformats/schemas/s$p$padsheetml/x2006/main/CTPivotTableDefinition.java.
AreaReference a=new AreaReference(new CellReference("A1"), new CellReference("E7"));
CellReference b=new CellReference("I5");
XSSFPivotTable pivotTable = sheet.createPivotTable(a,b);
pivotTable.addReportFilter(0);
pivotTable.addReportFilter(1);
pivotTable.addRowLabel(2);
pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldArray(2).setOutline(false);
pivotTable.addRowLabel(3);
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 4, "Sum");
这篇关于Apache的POI:Excel数据透视表 - 行标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!