https://bz.apache.org/bugzilla/show_bug.cgi?id=57798

            Bug ID: 57798
           Summary: Getting java.lang.IllegalStateException: Only formula
                    cells have cached results for array formulas
           Product: POI
           Version: 3.12-dev
          Hardware: PC
            Status: NEW
          Severity: major
          Priority: P2
         Component: XSSF
          Assignee: [email protected]
          Reporter: [email protected]

Created attachment 32637
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=32637&action=edit
xlsx version

The method cell.getCachedFormulaResultType() returns an exception when the cell
is part of an array formula and is not the first cell of the array formula.

This exception is not occurring with a HSSFWorkbook.

See sample code below and file attached.
You'll need to save the .xlsx version as .xls in Excel to run the working test
case.



import java.io.FileInputStream;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

public class TestXssf {

    public static void main(String[] args) throws Exception {

        String fileName = "Test.xlsx";
//        String fileName = "Test.xls";

        FileInputStream inputStream = new FileInputStream(fileName);
        Workbook workbook = WorkbookFactory.create(inputStream);

        Sheet sheet = workbook.getSheet("Sheet1");

        // *******************************
        // First cell of array formula, OK
        int rowId = 0;
        int cellId = 1;
        System.out.println("Reading row " + rowId + ", col " + cellId);

        Row row = sheet.getRow(rowId);
        Cell cell = row.getCell(cellId);

        System.out.println("Formula:" + cell.getCellFormula());
        if (Cell.CELL_TYPE_FORMULA == cell.getCellType()) {
            int formulaResultType = cell.getCachedFormulaResultType();
            System.out.println("Formual Result Type:" + formulaResultType);
        }

        // *******************************
        // Second cell of array formula, NOT OK for xlsx files  
        rowId = 1;
        cellId = 1;
        System.out.println("Reading row " + rowId + ", col " + cellId);

        row = sheet.getRow(rowId);
        cell = row.getCell(cellId);
        System.out.println("Formula:" + cell.getCellFormula());

        if (Cell.CELL_TYPE_FORMULA == cell.getCellType()) {
            int formulaResultType = cell.getCachedFormulaResultType();
            System.out.println("Formual Result Type:" + formulaResultType);
        }

        workbook.close();

    }
}

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to