你好,我看了上面的图片里的代码,好像是在异步自定义方法里面使用setArray来覆盖掉公式。常规方法是使用setAsyncResult,如下面代码示例
- spread.options.allowDynamicArray = true;
- var sheet = spread.getSheet(0);
- function FactorialArrayFunction() {
- this.name = "FACTORIAL.ARRAY";
- this.maxArgs = 1;
- this.minArgs = 1;
- }
- FactorialArrayFunction.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- FactorialArrayFunction.prototype.defaultValue = function () { return -1; };
- FactorialArrayFunction.prototype.evaluateAsync = function (context, arg) {
- var t = 1;
- var result = [[]];
- for (var i = 1; i <= arg; i++) {
- t = i * t;
- result[0].push(t);
- }
- setTimeout(()=>{
- context.setAsyncResult(new GC.Spread.CalcEngine.CalcArray(result));
- }, 2000);
- };
- var factorialArray = new FactorialArrayFunction();
-
- sheet.setValue(6, 1, 'Formula');
- sheet.setValue(6, 2, '=FACTORIAL.ARRAY(5)');
- sheet.setValue(7, 1, 'Result');
- sheet.addCustomFunction(factorialArray);
- sheet.setFormula(7, 2, "=FACTORIAL.ARRAY(5)");
- sheet.setFormula(8, 2, "=D8+F8");
复制代码
|