java使用ApachePOI将列标签插入透视表?
我已经使用ApachePOI3.11创建了一个透视表。像这样:
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
生成报告后,它正确地显示了行。但它不显示列标签:
我希望在透视表中显示列标签,如下所示:
(来源:pivot-table.com)
有人知道这个问题的解决办法吗
谢谢
# 1 楼答案
以下方法(XSSFPivotTable.addRowLabel的稍微修改版本)添加了一个“普通”数据透视列标签:
# 2 楼答案
从版本3.12 of POI开始,它就像一个符咒(也有自己的列标签):