I'm currently working on a Java application that uses the excel file(.xlsx) to create a pivot table in it.
From POI 3.11-beta1, I have found it support the creation of pivot tables. It makes me excited and I have tried the example for creating these tables which is available at https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreatePivotTable.java . It works! But when I try to read the data from the created pivot table using POI, it doesn't work.
In my testing code, I just add the following codes before the end '}' in the example:
// get the content of Cell "I7", should be "10"
FileInputStream fileInputStream = new FileInputStream("ooxml-pivottable.xlsx");
XSSFWorkbook xssfWorkbook = (XSSFWorkbook) WorkbookFactory.create(fileInputStream);
xssfWorkbook.setForceFormulaRecalculation(true);
Sheet sheet1 = xssfWorkbook.getSheetAt(0);
// Cell I7
Row row = sheet1.getRow(6);
if (row == null) {
System.out.println("Not expected: row is null");
return;
}
Cell cellI7 = row.getCell(8);
if (cellI7 != null && cellI7.getCellType() == Cell.CELL_TYPE_NUMERIC) {
System.out.println("The content of Cell I7 = "+cellI7.getNumericCellValue());
} else {
System.out.println("Not expected: cell is null");
return;
}
The console display: "Not expected: row is null". It seems to say "the created pivot table does not exist". I can't understand why it happens. So, is there another way to get/read/change the data from the created pivot tables with the POI api?
Thanks in Advanced!