use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class Match method evaluateMatchTypeArg.
private static double evaluateMatchTypeArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
ValueEval match_type = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
if (match_type instanceof ErrorEval) {
throw new EvaluationException((ErrorEval) match_type);
}
if (match_type instanceof NumericValueEval) {
NumericValueEval ne = (NumericValueEval) match_type;
return ne.getNumberValue();
}
if (match_type instanceof StringEval) {
StringEval se = (StringEval) match_type;
Double d = OperandResolver.parseDouble(se.getStringValue());
if (d == null) {
// plain string
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
// if the string parses as a number, it is OK
return d.doubleValue();
}
throw new RuntimeException("Unexpected match_type type (" + match_type.getClass().getName() + ")");
}
use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestSumif method testBasic.
public void testBasic() {
ValueEval[] arg0values = new ValueEval[] { _30, _30, _40, _40, _50, _50 };
ValueEval[] arg2values = new ValueEval[] { _30, _40, _50, _60, _60, _60 };
AreaEval arg0;
AreaEval arg2;
arg0 = EvalFactory.createAreaEval("A3:B5", arg0values);
arg2 = EvalFactory.createAreaEval("D1:E3", arg2values);
confirm(60.0, arg0, new NumberEval(30.0));
confirm(70.0, arg0, new NumberEval(30.0), arg2);
confirm(100.0, arg0, new StringEval(">45"));
confirm(100.0, arg0, new StringEval(">=45"));
confirm(100.0, arg0, new StringEval(">=50.0"));
confirm(140.0, arg0, new StringEval("<45"));
confirm(140.0, arg0, new StringEval("<=45"));
confirm(140.0, arg0, new StringEval("<=40.0"));
confirm(160.0, arg0, new StringEval("<>40.0"));
confirm(80.0, arg0, new StringEval("=40.0"));
}
use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestText method testTextWithDeciamlFormatSecondArg.
@Test
public void testTextWithDeciamlFormatSecondArg() {
ValueEval numArg = new NumberEval(321321.321);
ValueEval formatArg = new StringEval("#,###.00000");
ValueEval[] args = { numArg, formatArg };
ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short) -1);
DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(LocaleUtil.getUserLocale());
char groupSeparator = dfs.getGroupingSeparator();
char decimalSeparator = dfs.getDecimalSeparator();
ValueEval testResult = new StringEval("321" + groupSeparator + "321" + decimalSeparator + "32100");
assertEquals(testResult.toString(), result.toString());
numArg = new NumberEval(321.321);
formatArg = new StringEval("00000.00000");
args[0] = numArg;
args[1] = formatArg;
result = TextFunction.TEXT.evaluate(args, -1, (short) -1);
testResult = new StringEval("00321" + decimalSeparator + "32100");
assertEquals(testResult.toString(), result.toString());
formatArg = new StringEval("$#.#");
args[1] = formatArg;
result = TextFunction.TEXT.evaluate(args, -1, (short) -1);
testResult = new StringEval("$321" + decimalSeparator + "3");
assertEquals(testResult.toString(), result.toString());
}
use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestText method testTextWithStringFirstArg.
@Test
public void testTextWithStringFirstArg() {
ValueEval strArg = new StringEval("abc");
ValueEval formatArg = new StringEval("abc");
ValueEval[] args = { strArg, formatArg };
ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short) -1);
assertEquals(ErrorEval.VALUE_INVALID, result);
}
use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestTrim method testBasic.
public void testBasic() {
confirmTrim(new StringEval(" hi "), "hi");
confirmTrim(new StringEval("hi "), "hi");
confirmTrim(new StringEval(" hi"), "hi");
confirmTrim(new StringEval(" hi there "), "hi there");
confirmTrim(new StringEval(""), "");
confirmTrim(new StringEval(" "), "");
}
Aggregations