SpreadJS supports the Function Reference (also called "eta reduced lambda"). This feature simplifies a funciton by elminitating unnecessary abstractions and using abbreviated syntax when possible. The below demo shows some examples on how this can be used.
You can define a custom name with the content as the function name. Then you can use it in a formula.
spread.addCustomName("op","SUM");
sheet.setFormula(0,0,"op(B1:B5)");
You can use the function name as the LAMBDA functions parameter where lambda functions are accepted.
sheet.setFormula(0,0,"=LAMBDA(op,op(123))(SUM)");
sheet.setFormula(1,0,"=MAP(B1:C3,ABS)");
sheet.setFormula(2,0,"=BYCOL(B1:C3,SUM)");
sheet.setFormula(3,0,"=BYROW(B1:C3,SUM)");
sheet.setFormula(4,0,"=MAKEARRAY(3, 3, SUM)");
sheet.setFormula(5,0,"=REDUCE(True, B1:C2, AND)");
sheet.setFormula(6,0,"=SCAN(1, B1:C2, COUNT)");
sheet.setFormula(7,0,"=GROUPBY(B2:B34,D2:D34,SUM)");
You can define the name_value as a function reference, and then use it in the LET function
sheet.setFormula(0,0,"=LET(op,SUM,op(B1:B5))");
You can define the custom functions and use them for the above use cases.
function IsNegativeFunction() {
this.name = "ISNEGATIVE";
this.maxArgs = 1;
this.minArgs = 1;
}
IsNegativeFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
IsNegativeFunction.prototype.evaluate = function (arg) {
if (parseInt(arg)<0) {
return true;
}
return false;
};
spread.addCustomFunction(new IsNegativeFunction());
sheet.setFormula(4, 2, "=MAP(A1:C3,ISNEGATIVE)");
Submit and view feedback for