您好,可以直接重写,只要您自定义时设置的公式名称与要重写的公式名称相同即可。
示例代码:
- window.onload = function () {
- var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 1 });
- initSpread(spread);
- };
- function initSpread(spread) {
- 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 = "SUM";
- this.maxArgs = 1;
- this.minArgs = 1;
- }
- FactorialFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
- FactorialFunction.prototype.evaluate = function (arg) {
- var result = 1;
- if (arguments.length === 1 && !isNaN(parseInt(arg))) {
- for (var i = 1; i <= arg; i++) {
- result = i * result;
- }
- return result;
- }
- return "#VALUE!";
- };
- var factorial = new FactorialFunction();
- document.getElementById("addCustomFunction").addEventListener('click',function() {
- sheet.setValue(3, 1, 'Formula');
- sheet.setValue(3, 2, '=SUM(5)');
- sheet.setValue(4, 1, 'Result');
- sheet.addCustomFunction(factorial);
- sheet.setFormula(4, 2, "=SUM(5)");
- });
- document.getElementById("removeCustomFunction").addEventListener('click',function() {
- sheet.removeCustomFunction("SUM");
- });
- };
复制代码
|