Can't get the custom functions to work #980
Replies: 4 comments
-
@vhpoet I am sorry you experienced an issue with HyperFormula. Our guide on custom functions is outdated and contains misleading information. We will fix it soon (#968). Here is a working example of a simple custom function that you can use. It does not use the helper method In case of your code - it requires a few things to make it work:
After applying these fixes: import HyperFormula, { FunctionPlugin } from "hyperformula";
class MetricPlugin extends FunctionPlugin {
static implementedFunctions = {
METRIC: {
method: "metric",
parameters: []
}
};
static translations = {
'enGB': {
'METRIC': 'METRIC'
},
}
metric(ast, state) {
return this.runFunction(ast.args, state, this.metadata('METRIC'), () => 63);
}
}
export default function App() {
HyperFormula.registerFunctionPlugin(MetricPlugin, MetricPlugin.translations);
const hfInstance = HyperFormula.buildFromArray([["=METRIC()"]], {
licenseKey: "gpl-v3"
});
const value = hfInstance.getCellValue({ sheet: 0, col: 0, row: 0 });
console.log(value);
return null;
} |
Beta Was this translation helpful? Give feedback.
-
ok that works, thanks for the detailed answer! |
Beta Was this translation helpful? Give feedback.
-
@vhpoet With HyperFormula 2.0.1 we updated our guide about custom functions. You may want to have a look at it: https://handsontable.github.io/hyperformula/guide/custom-functions.html |
Beta Was this translation helpful? Give feedback.
-
@vhpoet, we've just released a new custom functions guide with an advanced example. You should check it out ;) |
Beta Was this translation helpful? Give feedback.
-
Followed your readme to come up with the below code which throws a
Function name METRIC not recognized.
. What am I doing wrong? Here's the codesandbox. Might be the same bug as this.Beta Was this translation helpful? Give feedback.
All reactions