Worksheet Functions

Calling functions written in Java using Jinx in Excel is exactly the same as calling any other Excel function written in VBA or as part of another Excel addin. They are called from formulas in an Excel worksheet in the same way, and appear in Excel’s function wizard.

Methods that are exposed as Excel functions are annotated using the @ExcelFunction annotation. They must be public methods, and can either be static or non-static (instance) methods. Classes with non-static methods must have a public default constructor.

For example, the following code adds a new function hello to Excel:

import com.exceljava.jinx.ExcelFunction;

class HelloFunction {
    @ExcelFunction
    public String hello(String name) {
        return String.format("Hello, %s!", name);
    }
}

Once that code is built the class HelloFunction can be added to the Jinx config file:

> javac -cp <path to jinx jar> HelloFunction.java
> jar -cf HelloFunction.jar HelloFunction.class
[JINX]
classes = HelloFunction

[JAVA]
classpath = ./HelloFunction.jar

Now when Excel is started the function hello exists and we can use it from a formula in a worksheet.

fib