我已经使用Apache POI 3.11创建了一个数据透视表。像这样:使用Apache POI将列标签插入数据透视表中?
FileInputStream file = new FileInputStream(new File(path+fname));
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
//area of pivot data
AreaReference a=new AreaReference("A1:J4");
CellReference b=new CellReference("N5");
XSSFPivotTable pivotTable = sheet.createPivotTable(a,b);
//insert row
pivotTable.addRowLabel(3);
pivotTable.addRowLabel(6);
//insert column
pivotTable.addColumnLabel(DataConsolidateFunction.COUNT, 5);
//export
FileOutputStream output_file =
new FileOutputStream(new File(path+"POI_XLS_Pivot_Example.xlsx"));
workbook.write(output_file);//write excel document to output stream
output_file.close(); //close the file
我生成报告后,它显示正确的行。不过,这并不表明列标签:
我想在我的透视表显示的列标签是这样的:
img http://www.pivot-table.com/wp-content/uploads/2010/12/calculateditem04.png
有谁知道这个问题的解决方案?
谢谢。
在这一刻我有完全一样的问题!那么,因为它是一个测试版本,现在可能不可能......可惜的是,没有方法'addColumnLabel(int)'这会添加没有数据合并功能的列标签......我搜索了一些示例代码,并发现这一点:https://code.google.com/p/web-design-r/source/browse/trunk/zpoiex-r/src/org/zkoss/zpoiex/ss/usermodel/helpers/PivotTableHelper。 java?r = 15 createPivotTable方法在处理一些'CTPivotField'的时候看起来很有趣。不知道,如果有通过这些领域的方式?! – bobbel 2014-10-29 17:07:36
你是否得到这个工作?创建addColumnLabel如下面的答案仍然无法正常工作..感谢 – labheshr 2016-05-27 16:48:16