minor fix to T() function, junit added

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@883039 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-11-22 05:49:51 +00:00
parent e09f868473
commit 18f9851823
2 changed files with 29 additions and 2 deletions

View File

@ -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) {

View File

@ -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, "");
}
}