简体   繁体   中英

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 . 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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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