本帖最后由 WilliamChang 于 2023-11-14 11:37 编辑
你好,参考如下代码看看能不能解决问题,添加asyncCount计数器,计数器为0时spread.resumePaint();:
- var asyncSum = function () {
- };
- asyncSum.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction("ASUM", 1, 255);
- asyncSum.prototype.defaultValue = function () {
- return "Loading...";
- };
- asyncSum.prototype.evaluateAsync = function (context) {
- // use setTimeout to simulate server side evaluation
- // in read world it maybe an ajax post to server for evaluation
- var args = arguments;
- window.asyncCount = (window.asyncCount || 0) + 1;
- setTimeout(function () {
- var result = 0;
- for (var i = 1; i < args.length; i++) {
- result += args[i];
- }
- result *= 2;
- context.setAsyncResult(result);
- window.asyncCount--;
- if (window.asyncCount <= 0) {
- setTimeout(function () {
- spread.resumePaint();
- });
- }
- }, 2000);
- };
- spread.addCustomFunction(new asyncSum());
- spread.suspendCalcService();
- spread.suspendPaint();
- spread.getActiveSheet().setFormula(0,0,"ASUM(2,3,4)");
- spread.getActiveSheet().setFormula(1,0,"ASUM(2,3,4)");
- spread.getActiveSheet().setFormula(2,0,"ASUM(2,3,4)");
- spread.getActiveSheet().setFormula(3,0,"ASUM(2,3,4)");
- spread.getActiveSheet().setFormula(4,0,"ASUM(2,3,4)");
- spread.calculate();
- spread.resumeCalcService();
复制代码 |