You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2009/11/22 06:49:51 UTC

svn commit: r883039 - in /poi/trunk/src: java/org/apache/poi/hssf/record/formula/functions/T.java testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java

Author: josh
Date: Sun Nov 22 05:49:51 2009
New Revision: 883039

URL: http://svn.apache.org/viewvc?rev=883039&view=rev
Log:
minor fix to T() function, junit added

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/T.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/T.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/T.java?rev=883039&r1=883038&r2=883039&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/T.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/T.java Sun Nov 22 05:49:51 2009
@@ -17,11 +17,19 @@
 
 package org.apache.poi.hssf.record.formula.functions;
 
+import org.apache.poi.hssf.record.formula.eval.AreaEval;
 import org.apache.poi.hssf.record.formula.eval.ErrorEval;
 import org.apache.poi.hssf.record.formula.eval.RefEval;
 import org.apache.poi.hssf.record.formula.eval.StringEval;
 import org.apache.poi.hssf.record.formula.eval.ValueEval;
 
+/**
+ * Implementation of Excel T() function
+ * <p/>
+ * If the argument is a text or error value it is returned unmodified.  All other argument types
+ * cause an empty string result.  If the argument is an area, the first (top-left) cell is used
+ * (regardless of the coordinates of the evaluating formula cell).
+ */
 public final class T implements Function {
 
     public ValueEval evaluate(ValueEval[] args, int srcCellRow, int srcCellCol) {
@@ -33,8 +41,10 @@
         }
         ValueEval arg = args[0];
         if (arg instanceof RefEval) {
-            RefEval re = (RefEval) arg;
-            arg = re.getInnerValueEval();
+            arg = ((RefEval) arg).getInnerValueEval();
+        } else if (arg instanceof AreaEval) {
+            // when the arg is an area, choose the top left cell
+            arg = ((AreaEval) arg).getRelativeValue(0, 0);
         }
 
         if (arg instanceof StringEval) {

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java?rev=883039&r1=883038&r2=883039&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java Sun Nov 22 05:49:51 2009
@@ -19,6 +19,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.record.formula.eval.AreaEval;
 import org.apache.poi.hssf.record.formula.eval.BlankEval;
 import org.apache.poi.hssf.record.formula.eval.BoolEval;
 import org.apache.poi.hssf.record.formula.eval.ErrorEval;
@@ -112,4 +113,20 @@
 		eval = invokeTWithReference(ErrorEval.NAME_INVALID);
 		assertTrue(eval == ErrorEval.NAME_INVALID);
 	}
+
+	public void testAreaArg() {
+		ValueEval[] areaValues = new ValueEval[] {
+			new StringEval("abc"), new StringEval("def"),
+			new StringEval("ghi"), new StringEval("jkl"),
+		};
+		AreaEval ae = EvalFactory.createAreaEval("C10:D11", areaValues);
+
+		ValueEval ve;
+		ve = invokeT(ae);
+		confirmString(ve, "abc");
+
+		areaValues[0] = new NumberEval(5.0);
+		ve = invokeT(ae);
+		confirmString(ve, "");
+	}
 }



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