poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1431403 - in /poi/trunk/src: java/org/apache/poi/ss/formula/atp/IfError.java testcases/org/apache/poi/ss/formula/atp/TestIfError.java
Date Thu, 10 Jan 2013 15:08:23 GMT
Author: nick
Date: Thu Jan 10 15:08:22 2013
New Revision: 1431403

URL: http://svn.apache.org/viewvc?rev=1431403&view=rev
Log:
Patch from Johan from bug #54402 - fix IfError with indirect references

Modified:
    poi/trunk/src/java/org/apache/poi/ss/formula/atp/IfError.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/atp/IfError.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/atp/IfError.java?rev=1431403&r1=1431402&r2=1431403&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/atp/IfError.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/atp/IfError.java Thu Jan 10 15:08:22 2013
@@ -18,6 +18,7 @@
 package org.apache.poi.ss.formula.atp;
 
 import org.apache.poi.ss.formula.OperationEvaluationContext;
+import org.apache.poi.ss.formula.WorkbookEvaluator;
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.EvaluationException;
 import org.apache.poi.ss.formula.eval.ValueEval;
@@ -47,7 +48,7 @@ final class IfError implements FreeRefFu
 
 		ValueEval val;
 		try {
-			val = evaluateArgParity(args[0], args[1], ec.getRowIndex(), ec.getColumnIndex());
+			val = evaluateInternal(args[0], args[1], ec.getRowIndex(), ec.getColumnIndex());
 		} catch (EvaluationException e) {
 			return e.getErrorEval();
 		}
@@ -55,11 +56,12 @@ final class IfError implements FreeRefFu
 		return val;
 	}
 
-	private static ValueEval evaluateArgParity(ValueEval arg, ValueEval iferror, int srcCellRow,
int srcCellCol) throws EvaluationException {
+	private static ValueEval evaluateInternal(ValueEval arg, ValueEval iferror, int srcCellRow,
int srcCellCol) throws EvaluationException {
+		arg = WorkbookEvaluator.dereferenceResult(arg, srcCellRow, srcCellCol);
 		if(arg instanceof ErrorEval) {
 			return iferror;
 		} else {
 			return arg;
 		}
 	}
-}
\ No newline at end of file
+}

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java?rev=1431403&r1=1431402&r2=1431403&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java Thu Jan 10 15:08:22
2013
@@ -36,6 +36,7 @@ public class TestIfError extends TestCas
     /**
      * =IFERROR(210/35,\"Error in calculation\")"  Divides 210 by 35 and returns 6.0
      * =IFERROR(55/0,\"Error in calculation\")"    Divides 55 by 0 and returns the error
text
+     * =IFERROR(C1,\"Error in calculation\")"      References the result of dividing 55 by
0 and returns the error text
      */
     public static void testEvaluate(){
         Workbook wb = new HSSFWorkbook();
@@ -46,6 +47,7 @@ public class TestIfError extends TestCas
         // Create cells
         row1.createCell(0, Cell.CELL_TYPE_NUMERIC);
         row1.createCell(1, Cell.CELL_TYPE_NUMERIC);
+        row1.createCell(2, Cell.CELL_TYPE_NUMERIC);
         row2.createCell(0, Cell.CELL_TYPE_NUMERIC);
         row2.createCell(1, Cell.CELL_TYPE_NUMERIC);
 
@@ -54,18 +56,22 @@ public class TestIfError extends TestCas
         CellReference a2 = new CellReference("A2");
         CellReference b1 = new CellReference("B1");
         CellReference b2 = new CellReference("B2");
+        CellReference c1 = new CellReference("C1");
         
         // Set values
         sh.getRow(a1.getRow()).getCell(a1.getCol()).setCellValue(210);
         sh.getRow(a2.getRow()).getCell(a2.getCol()).setCellValue(55);
         sh.getRow(b1.getRow()).getCell(b1.getCol()).setCellValue(35);
         sh.getRow(b2.getRow()).getCell(b2.getCol()).setCellValue(0);
+        sh.getRow(c1.getRow()).getCell(c1.getCol()).setCellFormula("A1/B2");
         
         Cell cell1 = sh.createRow(3).createCell(0);
         cell1.setCellFormula("IFERROR(A1/B1,\"Error in calculation\")");
         Cell cell2 = sh.createRow(3).createCell(0);
         cell2.setCellFormula("IFERROR(A2/B2,\"Error in calculation\")");
-
+        Cell cell3 = sh.createRow(3).createCell(0);
+        cell3.setCellFormula("IFERROR(C1,\"error\")");
+        
         double accuracy = 1E-9;
 
         FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
@@ -80,5 +86,10 @@ public class TestIfError extends TestCas
         		Cell.CELL_TYPE_STRING, evaluator.evaluate(cell2).getCellType());        
         assertEquals("Rounds -10 to a nearest multiple of -3 (-9)",
                 "Error in calculation", evaluator.evaluate(cell2).getStringValue());
+        
+        assertEquals("Check that C1 returns string", 
+        		Cell.CELL_TYPE_STRING, evaluator.evaluate(cell3).getCellType());
+        assertEquals("Check that C1 returns string \"error\"", 
+        		"error", evaluator.evaluate(cell3).getStringValue());
     }
-}
\ No newline at end of file
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message