I downloaded the latest version and that did not fix the issue.
Here's a code snippet...
XSSFWorkbook wbook = new XSSFWorkbook();XSSFSheet sheet =
wbook.createSheet("Formula Test");XSSFRow row = sheet.createRow(0);XSSFCell
cell1 = row.createCell(0);XSSFCell cell2 = row.createCell(1);XSSFCell cell3 =
row.createCell(2);XSSFCell cell4 = row.createCell(3);
cell1.setCellType(Cell.CELL_TYPE_STRING);
cell2.setCellType(Cell.CELL_TYPE_NUMERIC);
cell3.setCellType(Cell.CELL_TYPE_NUMERIC);cell4.setCellType(Cell.CELL_TYPE_FORMULA);cell1.setCellValue("1");cell2.setCellValue(2.0);cell3.setCellValue(3.0);cell4.setCellFormula("IF(A1=1,
A2, A3)");
FormulaEvaluator eval = wbook.getCreationHelper().createFormulaEvaluator();
switch(eval.evaluateFormulaCell(cell4)) { case Cell.CELL_TYPE_NUMERIC:
System.out.println(cell4.getNumericCellValue()); break;
case Cell.CELL_TYPE_STRING:
System.out.println(cell4.getStringCellValue()); break; case
Cell.CELL_TYPE_ERROR:
System.out.println(cell4.getErrorCellString()); break; }
Jason.
> Date: Thu, 5 Nov 2015 15:46:02 -0800
> Subject: RE: Formula not working as expected
> From: [email protected]
> To: [email protected]
>
> Keep this in mind:
> From http://poi.apache.org/spreadsheet/eval.html:
> "*Using** FormulaEvaluator.evaluate**(Cell cell)*
>
> This evaluates a given cell, and returns the new value, without affecting
> the cell"
> On 5 Nov 2015 3:41 p.m., "Jason Tomforde" <[email protected]> wrote:
>
> > If you are referring to this ...
> > CellValue cellValue = evaluator.evaluate(cell);
> >
> > Then yes.
> >
> > Most likely not the latest version.... I will give that a shot.
> >
> > Thank you,
> > Jason.
> >
> > > Date: Thu, 5 Nov 2015 23:36:20 +0000
> > > From: [email protected]
> > > To: [email protected]
> > > Subject: Re: Formula not working as expected
> > >
> > > On Thu, 5 Nov 2015, Jason Tomforde wrote:
> > > > A1 string cell = 1
> > > > A2 numeric cell = 2
> > > > A3 numeric cell = 3
> > > > A4 formula cell = IF(A1=1,A2,A3)
> > > >
> > > > The result I am getting is 0.
> > > >
> > > > Any thoughts?
> > >
> > > Are you evaluating the formula when you're doing with settings cells?
> > > http://poi.apache.org/spreadsheet/eval.html
> > >
> > > Are you using a new enough version of Apache POI?
> > > http://poi.apache.org/download.html
> > >
> > > Nick
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [email protected]
> > > For additional commands, e-mail: [email protected]
> > >
> >