SpreadJS Documentation
addCustomFunction Method
The function to add.
Adds the specified user-defined custom function to the collection.
Syntax
var instance = new GcSpread.Sheets.Sheet(name);
var value; // Type: any
value = instance.addCustomFunction(fn);
function addCustomFunction( 
   fn : Object
) : any;

Parameters

fn
The function to add.
Example
These examples create custom functions.
// Type =factorial(5) in a cell to see the result
function FactorialFunction() {
this.name = "FACTORIAL";
this.maxArgs = 1;
this.minArgs = 1;
}
FactorialFunction.prototype = new GcSpread.Sheets.Calc.Functions.Function();
FactorialFunction.prototype.evaluate = function (args) {
var result = 1;
if (args.length === 1 && !isNaN(parseInt(args[0]))) {
for (var i = 1; i < args[0]; i++) {
result = i * result;
}
return result;
}
return "#VALUE!";
}
var factorial = new FactorialFunction();
activeSheet.addCustomFunction(factorial);
activeSheet.getCell(0,0).formula("factorial(5)");
var name = activeSheet.getCustomFunction("factorial");
alert(name);
// Type =factorial(5) in a cell to see the result
function FactorialFunction() {
    this.name = "FACTORIAL";
    this.maxArgs = 1;
    this.minArgs = 1;
  }
FactorialFunction.prototype = new GcSpread.Sheets.Calc.Functions.Function();
FactorialFunction.prototype.evaluate = function (args) {
var result = 1;
if (args.length === 1 && !isNaN(parseInt(args[0]))) {
  for (var i = 1; i < args[0]; i++) {
      result = i * result;
    }
  return result;
  }
return "#VALUE!";
}
var factorial = new FactorialFunction();
activeSheet.addCustomFunction(factorial);
See Also

Reference

Sheet type

 

 


Copyright © GrapeCity, inc. All rights reserved.

Send comments on this topic.