Bug 62216 - SXSSFCell.setCellErrorValue turns a formula cell into an error cell, unlike XSSF
Summary: SXSSFCell.setCellErrorValue turns a formula cell into an error cell, unlike XSSF
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: SXSSF (show other bugs)
Version: 3.17-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-23 22:56 UTC by gallon.fizik@gmail.com
Modified: 2018-04-02 16:01 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gallon.fizik@gmail.com 2018-03-23 22:56:25 UTC
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);
Comment 1 PJ Fanning 2018-04-01 16:18:18 UTC
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?
Comment 2 gallon.fizik@gmail.com 2018-04-02 08:09:43 UTC
(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);
    }
}
Comment 3 PJ Fanning 2018-04-02 13:05:53 UTC
Hi Gallon,
That test passes even without the change in https://svn.apache.org/viewvc?view=revision&revision=1828144
Comment 4 gallon.fizik@gmail.com 2018-04-02 13:17:09 UTC
(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.
Comment 5 PJ Fanning 2018-04-02 16:00:59 UTC
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.