Interface UserFunction

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface UserFunction
A numeric user-defined formula function. Register it with Workbook.registerFunction(name, fn); the engine calls it when a formula uses that name, ignoring case.

Each argument arrives as one double: a blank counts as 0, TRUE/FALSE as 1/0, and numeric text as its number. Other text, an error value or a range argument arrives as NaN. For range arguments use TypedUserFunction. The return value becomes the formula's number.

If the function throws, the native bridge clears the exception and the formula evaluates to #VALUE!. The function must not call back into the same workbook while it runs.


 workbook.registerFunction("HYPOT", a -> Math.hypot(a[0], a[1]));
 sheet.cell(0, 0).setFormula("HYPOT(3,4)");   // 5
 
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    apply(double[] args)
    Computes the function result.
  • Method Details

    • apply

      double apply(double[] args)
      Computes the function result.
      Parameters:
      args - one value per formula argument, coerced as described above; non-numeric arguments are NaN
      Returns:
      the formula's numeric result