我已經使用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