Archive for May 2008
Registering Functions
XLLoop provides two mechanisms for calling functions on a server:
- A generic function (“FS” by default) that takes a function name and then a variable number of arguments.
- A dynamic function registration mechanism.
The function registration mechanism works by calling the function server (on excel startup or activation of the add-in) with a “GetFunctions” generic request. The server (ie. your server) implements this request handler and returns a collection of function definitions encoded as variants.
The easiest way to return the correct response is to use the FunctionInformation class. This provides an encode method that generates the format required for a single function. Simply add the encoding of multiple FunctionInformation objects to a VTCollection class and return this as a result. The follow code snippet shows the detail:
VTCollection collection = new VTCollection();
FunctionInformation fi = new FunctionInformation("Math.pow");
fi.setFunctionHelp("Raises the first value to the power of the second");
fi.setCategory("Maths");
fi.addArgument("value", "The first value");
fi.addArgument("power", "The power value");
collection.add(fi.encode());
This will expose “Math.pow” as a function in excel. When this function is called from excel, XLLoop (the XLL) will call your function handler, passing “Math.pow” as the function name and the arguments as a VTCollection.