package org.apache.poi.ss.formula.functions;
+import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.formula.eval.*;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.util.LocaleUtil;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import java.io.IOException;
import java.util.Locale;
import static org.junit.jupiter.api.Assertions.assertEquals;
"Math.E evals to invalid");
}
+ @Test
+ void testTimeValueInHSSF() throws IOException {
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
+ HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+ HSSFSheet sheet = wb.createSheet();
+ HSSFRow row = sheet.createRow(0);
+ row.createCell(0).setCellValue("8/22/2011 12:00");
+ HSSFCell cell = row.createCell(1);
+ confirmNumericResult(fe, cell, "TIMEVALUE(A1)", 0.5);
+ }
+ }
+
private ValueEval invokeTimeValue(ValueEval text) {
return new TimeValue().evaluate(0, 0, text);
}
assertEquals(ErrorEval.class, result.getClass());
assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), ((ErrorEval) result).getErrorCode());
}
+
+ private static void confirmNumericResult(HSSFFormulaEvaluator fe, HSSFCell cell, String formulaText, double expectedResult) {
+ cell.setCellFormula(formulaText);
+ fe.notifyUpdateCell(cell);
+ CellValue result = fe.evaluate(cell);
+ assertEquals(result.getCellType(), CellType.NUMERIC);
+ assertEquals(expectedResult, result.getNumberValue());
+ }
}