mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
[bug-66181] support VALUE function where input is a blank cell
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1905308 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
82e3102132
commit
6d0dbe6f95
@ -17,6 +17,7 @@
|
||||
|
||||
package org.apache.poi.ss.formula.functions;
|
||||
|
||||
import org.apache.poi.ss.formula.eval.BlankEval;
|
||||
import org.apache.poi.ss.formula.eval.ErrorEval;
|
||||
import org.apache.poi.ss.formula.eval.EvaluationException;
|
||||
import org.apache.poi.ss.formula.eval.NumberEval;
|
||||
@ -53,6 +54,9 @@ public final class Value extends Fixed1ArgFunction implements ArrayFunction {
|
||||
return e.getErrorEval();
|
||||
}
|
||||
String strText = OperandResolver.coerceValueToString(veText);
|
||||
if (veText == BlankEval.instance) {
|
||||
return new NumberEval(0.0);
|
||||
}
|
||||
if (StringUtil.isBlank(strText)) {
|
||||
return ErrorEval.VALUE_INVALID;
|
||||
}
|
||||
|
||||
@ -19,12 +19,20 @@ package org.apache.poi.ss.formula.functions;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.formula.eval.ErrorEval;
|
||||
import org.apache.poi.ss.formula.eval.NumberEval;
|
||||
import org.apache.poi.ss.formula.eval.StringEval;
|
||||
import org.apache.poi.ss.formula.eval.ValueEval;
|
||||
import org.apache.poi.ss.util.Utils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Tests for {@link Value}
|
||||
*/
|
||||
@ -97,4 +105,17 @@ final class TestValue {
|
||||
confirmValueError("1e2.5");
|
||||
confirmValueError("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBlank() throws IOException {
|
||||
try (HSSFWorkbook wb = new HSSFWorkbook()) {
|
||||
HSSFSheet sheet = wb.createSheet();
|
||||
HSSFRow row = sheet.createRow(0);
|
||||
HSSFCell b1 = row.createCell(1);
|
||||
HSSFCell c1 = row.createCell(2);
|
||||
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
||||
Utils.assertDouble(fe, b1, "VALUE(A1)", 0.0);
|
||||
Utils.assertDouble(fe, c1, "VALUE(B1)", 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user