use of org.apache.poi.ss.formula.OperationEvaluationContext in project poi by apache.
the class TestWorkbook method testAddNameX.
@Test
public void testAddNameX() throws IOException {
HSSFWorkbook hwb = new HSSFWorkbook();
InternalWorkbook wb = TestHSSFWorkbook.getInternalWorkbook(hwb);
assertNotNull(wb.getNameXPtg("ISODD", AggregatingUDFFinder.DEFAULT));
FreeRefFunction NotImplemented = new FreeRefFunction() {
@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
throw new RuntimeException("not implemented");
}
};
/*
* register the two test UDFs in a UDF finder, to be passed to the evaluator
*/
UDFFinder udff1 = new DefaultUDFFinder(new String[] { "myFunc" }, new FreeRefFunction[] { NotImplemented });
UDFFinder udff2 = new DefaultUDFFinder(new String[] { "myFunc2" }, new FreeRefFunction[] { NotImplemented });
UDFFinder udff = new AggregatingUDFFinder(udff1, udff2);
assertNotNull(wb.getNameXPtg("myFunc", udff));
assertNotNull(wb.getNameXPtg("myFunc2", udff));
// myFunc3 is unknown
assertNull(wb.getNameXPtg("myFunc3", udff));
hwb.close();
}
use of org.apache.poi.ss.formula.OperationEvaluationContext in project poi by apache.
the class TestDec2Bin method createContext.
private OperationEvaluationContext createContext() {
HSSFWorkbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("13.43");
cell = row.createCell(1);
cell.setCellValue("8");
cell = row.createCell(2);
cell.setCellValue("-8");
cell = row.createCell(3);
cell.setCellValue("1");
HSSFEvaluationWorkbook workbook = HSSFEvaluationWorkbook.create(wb);
WorkbookEvaluator workbookEvaluator = new WorkbookEvaluator(workbook, new IStabilityClassifier() {
@Override
public boolean isCellFinal(int sheetIndex, int rowIndex, int columnIndex) {
return true;
}
}, null);
OperationEvaluationContext ctx = new OperationEvaluationContext(workbookEvaluator, workbook, 0, 0, 0, null);
return ctx;
}
use of org.apache.poi.ss.formula.OperationEvaluationContext in project poi by apache.
the class TestDec2Bin method testEvalOperationEvaluationContext.
public void testEvalOperationEvaluationContext() {
OperationEvaluationContext ctx = createContext();
ValueEval[] args = new ValueEval[] { ctx.getRefEval(0, 0) };
ValueEval result = new Dec2Bin().evaluate(args, ctx);
assertEquals(StringEval.class, result.getClass());
assertEquals("1101", ((StringEval) result).getStringValue());
}
use of org.apache.poi.ss.formula.OperationEvaluationContext in project poi by apache.
the class TestDec2Bin method testWithErrorPlaces.
public void testWithErrorPlaces() {
OperationEvaluationContext ctx = createContext();
ValueEval[] args = new ValueEval[] { ctx.getRefEval(0, 0), ErrorEval.NULL_INTERSECTION };
ValueEval result = new Dec2Bin().evaluate(args, -1, -1);
assertEquals(ErrorEval.class, result.getClass());
assertEquals(ErrorEval.NULL_INTERSECTION, result);
}
use of org.apache.poi.ss.formula.OperationEvaluationContext in project poi by apache.
the class TestBin2Dec method testEvalOperationEvaluationContext.
public void testEvalOperationEvaluationContext() {
OperationEvaluationContext ctx = createContext();
ValueEval[] args = new ValueEval[] { ctx.getRefEval(0, 0) };
ValueEval result = new Bin2Dec().evaluate(args, ctx);
assertEquals(NumberEval.class, result.getClass());
assertEquals("0", ((NumberEval) result).getStringValue());
}
Aggregations