aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2009-11-22 05:49:51 +0000
committerJosh Micich <josh@apache.org>2009-11-22 05:49:51 +0000
commit8f2e06a754974aba79f64d604ede3e9573dd5c04 (patch)
treeb506db95b0b5b8c1cc8af552a4429aeeb4d9945d /src
parentbfd968deb39f8f4638e81aa60e1c2738c1c9c5ea (diff)
downloadpoi-8f2e06a754974aba79f64d604ede3e9573dd5c04.tar.gz
poi-8f2e06a754974aba79f64d604ede3e9573dd5c04.zip
minor fix to T() function, junit added
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@883039 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/functions/T.java14
-rw-r--r--src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java17
2 files changed, 29 insertions, 2 deletions
diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/T.java b/src/java/org/apache/poi/hssf/record/formula/functions/T.java
index 54e31f8b48..e4b43c0d1c 100644
--- a/src/java/org/apache/poi/hssf/record/formula/functions/T.java
+++ b/src/java/org/apache/poi/hssf/record/formula/functions/T.java
@@ -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 @@ public final class T implements Function {
}
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) {
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java
index 53482c86c8..8a502c20cc 100644
--- a/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/functions/TestTFunc.java
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.record.formula.functions;
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 @@ public final class TestTFunc extends TestCase {
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, "");
+ }
}