Hi,
I am using HyberFormulas. In this, I am trying to do some calculations using custom functions.
I want to pass arguments (another cell value) in custom functions to perform calculations. Is there any way to achieve this?
Ex: =calculate("=A1") + 3
Hi @adrian.szymanski ,
if i pass any value directly to custom function, i can get that value in āast.argsā. so i can proceed further. But I am passing argument as a named expression in custom functions. i am not able to get the value of named expression in āast.argsā.
Could you help on this scenario. Handsontable example - JSFiddle - Code Playground
Hi @jubilee.mohamed
I have consulted this with my colleague and it turned out that this is the issue reported here:
Description
As discussed here, we should add a more advanced guide on implementng custom functions.
Links
https://handsontable.github.io/hyperformula/guide/custom-functions.html#implementing-your-custom-function
#968
#1090
Type of issue
Missing documentation
Error in the...
Docs
Verified
Impact: High
I will get back to you next week with more information on this.
Hi @jubilee.mohamed
I just received more information on this issue.
This is a custom function that accepts a parameter. Itās still in the development stage, and it will be published in the next version of our documentation, but you may want to look at it and implement your custom function in a similar way: https://codesandbox.io/s/github/handsontable/hyperformula-demos/tree/feature/issue-779/custom-functions
Does it solve your problem?
Hi @adrian.szymanski ,
Sorry for the delay response. Thanks for the solution on custom functionās argument related issue.
I have verified this code in all way. It returns cell reference and named expression value. Thanks.
But when i use multiple params using comma it returns error.
Ex. =GREET(A1) working
=GREET(A1,12345) working
=GREET(A1,āPRODUCTā) It is not working.
i have using this for multiple param,
GreetingsPlugin.implementedFunctions = {
GREET: {
method: āgreetā,
parameters: [{ argumentType: āSTRINGā }, { argumentType: āSTRINGā }]
}
};
Hi @jubilee.mohamed
Iāve asked our Hyperfomula developer for an advice on this. Iāll get back to you when I have more info.
1 Like
Hi @jubilee.mohamed
HyperFormula accepts string parameters in double-quotes. Try this:
=GREET(A1, "PRODUCT")
Hi @adrian.szymanski ,
I missed to pass multiple params.
ex:
greet(ast, state) {
return this.runFunction(
ast.args,
state,
this.metadata(āGREETā),
(username,param) => {
if (!username) {
return new CellError(āVALUEā);
}
return `š Hello, ${username}!`;
}
It is working and returns value as expected. It is helped me a lots.
Thank you @adrian.szymanski
Hi @jubilee.mohamed
Thatās great. Iām glad that we could help!
1 Like