Repository navigation
Can't get the custom functions to work #980
Replies: 5 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;
} |
|
ok that works, thanks for the detailed answer! |
|
@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 |
|
@vhpoet, we've just released a new custom functions guide with an advanced example. You should check it out ;) |
|
Please note that HyperFormula feature requests have been moved to the Handsontable forums: |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.All reactions