A fix for this seems to be a one-liner. In source @Override public void setCellErrorValue(byte value) { ensureType(CellType.ERROR); if(_value.getType()==CellType.FORMULA) ((ErrorFormulaValue)_value).setPreEvaluatedValue(value); else ((ErrorValue)_value).setValue(value); } ensureType(CellType.ERROR); is to be replaced by ensureTypeOrFormulaType(CellType.ERROR);
I added the suggested change using https://svn.apache.org/viewvc?view=revision&revision=1828144 Would it be possible to get a test case for regression purposes?
(In reply to PJ Fanning from comment #1) > I added the suggested change using > https://svn.apache.org/viewvc?view=revision&revision=1828144 > > Would it be possible to get a test case for regression purposes? import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.FormulaError; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.junit.Test; import static org.junit.Assert.assertEquals; public class SXSSFCellTest { @Test public void test62216() { Cell instance = new SXSSFWorkbook().createSheet().createRow(0).createCell(0); String formula = "2"; instance.setCellFormula(formula); instance.setCellErrorValue(FormulaError.NAME.getCode()); String result = instance.getCellFormula(); assertEquals(formula, result); } }
Hi Gallon, That test passes even without the change in https://svn.apache.org/viewvc?view=revision&revision=1828144
(In reply to PJ Fanning from comment #3) > Hi Gallon, > That test passes even without the change in > https://svn.apache.org/viewvc?view=revision&revision=1828144 That's weird. With poi 3.17 it fails for me with java.lang.IllegalStateException: Cannot get a FORMULA value from a ERROR cell. It passes with an XSSFWorkbook, though. When I have time, I can check out trunk and try it myself.
The test case works with and without the change with poi trunk (4.0.0 pre release) but does fail with 3.17 code base. I've added the test case to trunk.