Arrays and Array Types
Methods exposed to Excel as UDFs can accepts cell ranges as arguments. Array arguments can be arrays of any type recognized by Jinx, including custom types and cached objects.
Jinx methods may accept 1d or 2d arrays. When passed a range of cells, if a 2d array is used then that array has the same dimensions as the range passed in. 1d arrays are useful for functions that expect a row or column of data.
Functions may also return arrays. In Excel, these functions are termed array formulas and are entered slightly differently from normal formulas:
- Select the range of cells for the formula (this where the results will appear).
- Enter the formula (i.e the function you are calling).
- Press Ctrl+Shift+Enter.
Sometimes the caller of a function won’t know the exact size of the results they are expecting. For this reason, Jinx can automatically resize the output formula based on the dimensions of the array returned. This feature is enabled by passing autoResize=true to @ExcelFunction.
The following is an example of a function that takes an array and returns an array.
Lists and Other Collection Types
While Jinx will handle array types automatically, it doesn’t handle Lists or other collection types by default.
If you want to be able to write functions that, for example, take a List
instead of
an array you can do so by adding a generic type converter.