简体   繁体   English

如何从 SXSSFWorkbook - APACHE POI 创建 PIVOT 表

[英]How to create the PIVOT table from SXSSFWorkbook - APACHE POI

This is the Case: I am getting SXSSFWorkbook object and i need to create the pivot table by using that object .这是案例:我正在获取 SXSSFWorkbook 对象,我需要使用该对象创建数据透视表。 Is any way we can achieve it.有什么办法可以实现。

I have checked the below link: Apache POI - is there a way to create a pivot table where the source table is a SXSSFSheet?我检查了以下链接: Apache POI - 有没有办法在源表是 SXSSFSheet 的情况下创建数据透视表?

But in this case first we are creating XSSFWorkbook and later we are creating SXSSFworkbook.Is there any way by using SXSSFworkbook we can achieve this or by creating XSSFWorkbook to achieve pivottable and later is it possible to integrate to existing SXSSFWorkbook.但在这种情况下,我们首先创建 XSSFWorkbook,然后创建 SXSSFworkbook。

Resolved the above issue ,please find the below code.解决了上面的问题,请找到下面的代码。

     SXSSFWorkbook swb=null;
    XSSFSheet pivotSheet=null;
    AreaReference areaReference=null;
    if(wb instanceof SXSSFWorkbook ) {
        swb =(SXSSFWorkbook)wb;
        pivotSheet= swb.getXSSFWorkbook().createSheet("Pivot Sheet");
        SXSSFSheet sxssfDataSheet = (SXSSFSheet) sheet;
        areaReference = new AreaReference("A1:K"+(sxssfDataSheet.getLastRowNum() + 1), SpreadsheetVersion.EXCEL2007);
    }else {
        wb.createSheet("Pivot Sheet");
        pivotSheet = (XSSFSheet) wb.getSheetAt(1); 
        XSSFSheet  xssfDataSheet = (XSSFSheet) sheet;
        areaReference = new AreaReference("A1:K"+(xssfDataSheet.getLastRowNum() + 1), SpreadsheetVersion.EXCEL2007);
    }

After we get this objects, then we can construct the pivot structure according to our requirement.拿到这些对象后,我们就可以根据自己的需求构造pivot结构了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM