0

I am creating pivot table using poi and save it into another sheet but after that i want to read the data of recently created pivot table but somehow i could't get it For creating Pivot i am using:

    File file = new File(filepath);
    try (FileInputStream inputStream = new FileInputStream(file);)

    {

        XSSFWorkbook testData = null;
        testData = new XSSFWorkbook(inputStream);
        XSSFSheet testDataSheet = testData.getSheet(sheetname);
        XSSFSheet sheet2 = testData.createSheet("pivot");
        XSSFPivotTable pivotTable = sheet2.createPivotTable(new AreaReference(range, null), new CellReference("A1"), testDataSheet);

        pivotTable.addRowLabel(rownum);
        pivotTable.addColumnLabel(dataConsolidateFunction, value);

        FileOutputStream fileOut = new FileOutputStream(pivotsheetpath);
        testData.write(fileOut);
        fileOut.close();
        inputStream.close();
        testData.close();

    }

}

getting data from excel:

    String[][] data = null;
    File file = new File(filePath);

    try (FileInputStream inputStream = new FileInputStream(file);)
    {

        int row = 0;
        int column = 0;

        DataFormatter dataFormatter = new DataFormatter();

        XSSFWorkbook testData = null;
        String fileExtensionName = FilenameUtils.getExtension(filePath);
        if (fileExtensionName.equals("xlsx"))
            testData = new XSSFWorkbook(inputStream);

        XSSFSheet testDataSheet = testData.getSheet(sheetName);
        row = testDataSheet.getLastRowNum() - testDataSheet.getFirstRowNum();
        column = testDataSheet.getRow(0).getLastCellNum() - testDataSheet.getRow(0).getFirstCellNum();
        data = new String[row + 1][column];

        for (Row rows : testDataSheet)
            for (Cell cell : rows)
                data[rows.getRowNum()][cell.getColumnIndex()] = dataFormatter.formatCellValue(cell);
        testData.close();
        return data;
    }
4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.