请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册

QQ登录

只需一步,快速开始

kilozhou

注册会员

1

主题

1

帖子

4

积分

注册会员

积分
4
最新发帖
kilozhou
注册会员   /  发表于:2018-12-7 15:00  /   查看:3589  /  回复:1
我定义了一个自定义函数,然后我直接在单元格里面输入=setcell("aa","bb"),这个时候,单元格里显示出了函数的结果,但是,在js里我通过hasFormula判断这个单元格,发现结果是false
但如果我在单元格里输入=sum(2,3),然后通过hasFormula判断,结果是true,
这个问题如何解决,就是自定义函数在单元格中hasFormula函数是false的问题,我想让hasFormula是true。

自定义函数是下面这个:
function SetCellFunction() {
    this.name = "SETCELL";
    this.maxArgs = 9999999;
    this.minArgs = 1;
}
SetCellFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
SetCellFunction.prototype.evaluate = function (arg) {
   
    var scriptStr = "";
   
    if (arguments.length % 2 != 0) {
    if (arguments.length != 1) {
        return "#VALUE!";
    } else {
        return arguments[0];
    }
   
    }
   
    var count = arguments.length / 2;
    scriptStr = arguments[0] + "{'" + arguments[1] + "'}";
   
    console.log(arguments.length);
   
    for (var i = 1; i < count; i++) {
    var columnNameId = i * 2;
    var dimensionMemberId = i * 2 + 1;
    //console.log(arguments[columnNameId] + "{'" + arguments[dimensionMemberId] + "'}");
    scriptStr += "," + arguments[columnNameId] + "{'" + arguments[dimensionMemberId] + "'}";
    }
   
    return scriptStr;
};
var setcell = new SetCellFunction();

1 个回复

倒序浏览
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2018-12-7 16:04:00
沙发
您好,我这边没能重现您的问题,如图:

image.png241638488.png

代码如下:

  1. $(document).ready(function () {
  2.         var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), {
  3.             sheetCount: 1
  4.         });
  5.         initSpread(spread);
  6.     });

  7.     function SetCellFunction() {
  8.         this.name = "SETCELL";
  9.         this.maxArgs = 9999999;
  10.         this.minArgs = 1;
  11.     }
  12.     SetCellFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
  13.     SetCellFunction.prototype.evaluate = function (arg) {

  14.         var scriptStr = "";
  15.         if (arguments.length % 2 != 0) {
  16.             if (arguments.length != 1) {
  17.                 return "#VALUE!";
  18.             } else {
  19.                 return arguments[0];
  20.             }
  21.         }
  22.         var count = arguments.length / 2;
  23.         scriptStr = arguments[0] + "{'" + arguments[1] + "'}";
  24.         console.log(arguments.length);
  25.         for (var i = 1; i < count; i++) {
  26.             var columnNameId = i * 2;
  27.             var dimensionMemberId = i * 2 + 1;
  28.             //console.log(arguments[columnNameId] + "{'" + arguments[dimensionMemberId] + "'}");
  29.             scriptStr += "," + arguments[columnNameId] + "{'" + arguments[dimensionMemberId] + "'}";
  30.         }

  31.         return scriptStr;
  32.     };


  33.     function initSpread(spread) {

  34.         var activeSheet = spread.getSheet(0);

  35.         activeSheet.suspendPaint();

  36.         var setcell = new SetCellFunction();

  37.         activeSheet.addCustomFunction(setcell);
  38.         activeSheet.setFormula(1, 1, "=SETCELL('aa','bb')");

  39.         activeSheet.resumePaint();
  40.     }
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部