window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 2 });
initSpread(spread);
};
function initSpread(spread) {
spread.options.allowDynamicArray = true;
var sheet = spread.getSheet(0);
sheet.setValue(1, 1, 'Press \'Add a Custom Function\' button');
sheet.setColumnWidth(1, 225);
sheet.setColumnWidth(2, 100);
function FactorialFunction() {
this.name = "FACTORIAL";
this.maxArgs = 1;
this.minArgs = 1;
}
FactorialFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
FactorialFunction.prototype.evaluate = function (arg) {
return null;
};
var factorial = new FactorialFunction();
sheet.addCustomFunction(factorial);
document.getElementById("addCustomFunction").addEventListener('click',function() {
sheet.setValue(3, 1, 'Formula');
sheet.setValue(3, 2, '=FACTORIAL(5)');
console.log(GC.Spread.Sheets.CalcEngine.evaluateFormula(sheet, "=FACTORIAL(5)"));
});
document.getElementById("removeCustomFunction").addEventListener('click',function() {
sheet.removeCustomFunction("FACTORIAL");
sheet.recalcAll(true);
});
};
|