use of org.apache.poi.ss.usermodel.CellValue in project poi by apache.
the class CountifsTests method testCallFunction.
/**
* Basic call
*/
@Test
public void testCallFunction() {
Sheet sheet = workbook.createSheet("test");
Row row1 = sheet.createRow(0);
Cell cellA1 = row1.createCell(0, CellType.FORMULA);
Cell cellB1 = row1.createCell(1, CellType.NUMERIC);
Cell cellC1 = row1.createCell(2, CellType.NUMERIC);
Cell cellD1 = row1.createCell(3, CellType.NUMERIC);
Cell cellE1 = row1.createCell(4, CellType.NUMERIC);
cellB1.setCellValue(1);
cellC1.setCellValue(1);
cellD1.setCellValue(2);
cellE1.setCellValue(4);
cellA1.setCellFormula("COUNTIFS(B1:C1,1, D1:E1,2)");
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
CellValue evaluate = evaluator.evaluate(cellA1);
assertEquals(1.0d, evaluate.getNumberValue(), 0.000000000000001);
}
use of org.apache.poi.ss.usermodel.CellValue in project poi by apache.
the class TestXSSFFormulaEvaluation method testBug55843d.
@Test
public void testBug55843d() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook();
try {
XSSFSheet sheet = wb.createSheet("test");
XSSFRow row = sheet.createRow(0);
XSSFRow row2 = sheet.createRow(1);
XSSFCell cellA2 = row2.createCell(0, CellType.FORMULA);
XSSFCell cellB1 = row.createCell(1, CellType.NUMERIC);
cellB1.setCellValue(10);
XSSFFormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
cellA2.setCellFormula("IF(NOT(B1=0),((ROW())),\"\")");
CellValue evaluateN = formulaEvaluator.evaluate(cellA2);
assertEquals("2.0", evaluateN.formatAsString());
} finally {
wb.close();
}
}
use of org.apache.poi.ss.usermodel.CellValue in project poi by apache.
the class TestXSSFFormulaEvaluation method testBug55843c.
@Test
public void testBug55843c() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook();
try {
XSSFSheet sheet = wb.createSheet("test");
XSSFRow row = sheet.createRow(0);
XSSFRow row2 = sheet.createRow(1);
XSSFCell cellA2 = row2.createCell(0, CellType.FORMULA);
XSSFCell cellB1 = row.createCell(1, CellType.NUMERIC);
cellB1.setCellValue(10);
XSSFFormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
cellA2.setCellFormula("IF(NOT(B1=0),((ROW())))");
CellValue evaluateN = formulaEvaluator.evaluate(cellA2);
assertEquals("2.0", evaluateN.formatAsString());
} finally {
wb.close();
}
}
use of org.apache.poi.ss.usermodel.CellValue in project poi by apache.
the class TestXSSFFormulaEvaluation method test59736.
@Test
public void test59736() {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("59736.xlsx");
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
Cell cell = wb.getSheetAt(0).getRow(0).getCell(0);
assertEquals(1, cell.getNumericCellValue(), 0.001);
cell = wb.getSheetAt(0).getRow(1).getCell(0);
CellValue value = evaluator.evaluate(cell);
assertEquals(1, value.getNumberValue(), 0.001);
cell = wb.getSheetAt(0).getRow(2).getCell(0);
value = evaluator.evaluate(cell);
assertEquals(1, value.getNumberValue(), 0.001);
}
use of org.apache.poi.ss.usermodel.CellValue in project poi by apache.
the class TestXSSFFormulaEvaluation method testBug55843f.
@Test
public void testBug55843f() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook();
try {
XSSFSheet sheet = wb.createSheet("test");
XSSFRow row = sheet.createRow(0);
XSSFRow row2 = sheet.createRow(1);
XSSFCell cellA2 = row2.createCell(0, CellType.FORMULA);
XSSFCell cellB1 = row.createCell(1, CellType.NUMERIC);
cellB1.setCellValue(10);
XSSFFormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
cellA2.setCellFormula("IF(B1=0,\"\",IF(B1=10,3,4))");
CellValue evaluate = formulaEvaluator.evaluate(cellA2);
assertEquals("3.0", evaluate.formatAsString());
} finally {
wb.close();
}
}
Aggregations