有什么方法可以使用Apache POI在Excel中创建数据透视表? [英] Is there any way to create a Pivot Table in Excel using Apache POI?

查看:194
本文介绍了有什么方法可以使用Apache POI在Excel中创建数据透视表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在致力于Excel的自动化,并添加了这样的内容,我充分利用了Apache POI库.

I am currently working on the automation of Excel, and add such I have made a good use of the Apache POI library.

由于我的excel工作簿中的各个列中存储了太多数据,因此我试图创建数据透视表.

As I have so much data stored in my excel workbook in various columns, that I'm trying to create a pivot table.

是否可以使用POI创建数据透视表?

我的要求是,我需要在新的Excel工作簿中或存储数据的同一工作簿中创建数据透视表.

My requirement is that I need to create the pivot table in a new excel workbook or in the same workbook where I store my data.

推荐答案

快速指南"已经过时.

更改日志指的是您可以看到代码这是一个代码段:

 public static void main(String[] args) throws FileNotFoundException, IOException, InvalidFormatException {
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = (XSSFSheet) wb.createSheet();

        //Create some data to build the pivot table on
        setCellData(sheet);

        XSSFPivotTable pivotTable = sheet.createPivotTable(new AreaReference("A1:D4"), new CellReference("H5"));
        //Configure the pivot table
        //Use first column as row label
        pivotTable.addRowLabel(0);
        //Sum up the second column
        pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1);
        //Set the third column as filter
        pivotTable.addColumnLabel(DataConsolidateFunction.AVERAGE, 2);
        //Add filter on forth column
        pivotTable.addReportFilter(3);

        FileOutputStream fileOut = new FileOutputStream("ooxml-pivottable.xlsx");
        wb.write(fileOut);
        fileOut.close();
    }

这篇关于有什么方法可以使用Apache POI在Excel中创建数据透视表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆