List of usage examples for org.apache.poi.ss.formula WorkbookEvaluator registerFunction
public static void registerFunction(String name, Function func)
From source file:com.dataart.spreadsheetanalytics.engine.SpreadsheetEvaluator.java
License:Apache License
protected static void loadCustomFunctions() throws ReflectiveOperationException { Map<String, Class<? extends ICustomFunction>> map = Functions.getCustomFunctions(); AnalysisToolPak._saFunctionsByName = new HashMap<>(); map.forEach((k, v) -> AnalysisToolPak._saFunctionsByName.put(k, null)); for (Entry<String, Class<? extends ICustomFunction>> en : map.entrySet()) { WorkbookEvaluator.registerFunction(en.getKey(), en.getValue().newInstance()); }//from w w w.j a v a 2s . c o m }
From source file:de.jlo.talendcomp.excel.SpreadsheetFile.java
License:Apache License
/** * register a function to POI//from w w w . ja va 2s. c om * @param name function name (use the English language name of the function!) * @param functionClassName class name of the function including package * @throws Exception if function cannot be loaded or instantiated */ public static void registerFunction(String name, String functionClassName) throws Exception { try { Object o = Class.forName(functionClassName).newInstance(); if (o instanceof Function) { Function f = (Function) o; WorkbookEvaluator.registerFunction(name, f); } else if (o instanceof FreeRefFunction) { FreeRefFunction f = (FreeRefFunction) o; WorkbookEvaluator.registerFunction(name, f); } else { throw new IllegalArgumentException("Register function: " + name + " failed: Class " + functionClassName + " is not a Function or a FreeRefFunction"); } } catch (ClassNotFoundException cnf) { throw new Exception("Register function name=" + name + " functionClassName=" + functionClassName + " failed:" + cnf.getMessage(), cnf); } }