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. If any argument is other text or a range, the function is not called and the formula is #VALUE!; an error value argument becomes the formula's value, as with a built-in such as ABS. For text or range arguments use TypedUserFunction. The return value becomes the formula's number; a NaN or infinite return value becomes #NUM!.

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
      Returns:
      the formula's numeric result