找回密码
 立即注册

QQ登录

只需一步,快速开始

nobt

论坛元老

86

主题

4195

帖子

4947

积分

论坛元老

积分
4947

微信认证勋章

nobt
论坛元老   /  发表于:2019-10-17 14:10  /   查看:3020  /  回复:6
1金币
  1. getFormulaFunction.prototype.acceptsReference = function (argIndex) {
  2.       if(argIndex === 0 || argIndex === 1 || argIndex === 2){
  3.             return true;
复制代码
请问自定义函数想用到多个引用参数,这样写有什么问题吗?
下面是我的函数定义基本信息:
  1. function getFormulaFunction() {
  2.                     this.name = "GETFORMULA";
  3.                     this.maxArgs = 3;
  4.                     this.minArgs = 1;
  5.                 }
  6.                 getFormulaFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
  7. <blockquote>getFormulaFunction.prototype.acceptsReference = function (argIndex) {
  8.       if(argIndex === 0 || argIndex === 1 || argIndex === 2){
  9.             return true;
复制代码
想达到的效果如图:
image.png167436827.png
说明:第一个参数用来指定区域,第二个参数和第三个参数用作指定输出单元格备用

最佳答案

查看完整内容

您好: 在公式中去设置其他单元格的值是一个未知的有风险的事情,不是我们推荐的做法,首先公式之间是存在相互引用关系的,如果在一个公式计算的返回结果中去设置另一个单元格的值,可能会存在循环引用的问题。例如:公式的计算参数包含A3这个单元格,然后在公式的计算方法中去给A3这个单元格设置一个值,就会造成循环应用,设置值之后又会触发公式的计算。这样会出现不可预知的问题。如果人为避免此情况,理论上是可以的,参考 ...

6 个回复

倒序浏览
最佳答案
最佳答案
Clark.Pan讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2019-10-17 14:10:44
来自 8#
您好:

在公式中去设置其他单元格的值是一个未知的有风险的事情,不是我们推荐的做法,首先公式之间是存在相互引用关系的,如果在一个公式计算的返回结果中去设置另一个单元格的值,可能会存在循环引用的问题。例如:公式的计算参数包含A3这个单元格,然后在公式的计算方法中去给A3这个单元格设置一个值,就会造成循环应用,设置值之后又会触发公式的计算。这样会出现不可预知的问题。如果人为避免此情况,理论上是可以的,参考附件demo

customfunction_acceptsReference.html

1.66 KB, 下载次数: 50

回复 使用道具 举报
Clark.Pan讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2019-10-17 15:43:34
2#
您现在遇到什么问题了吗?
回复 使用道具 举报
nobt
论坛元老   /  发表于:2019-10-17 15:47:51
3#
1、函数不能正常运作
2、CPU可以拉成100%
回复 使用道具 举报
nobt
论坛元老   /  发表于:2019-10-17 15:48:03
4#
ClarkPan 发表于 2019-10-17 15:43
您现在遇到什么问题了吗?

1、函数不能正常运作
2、CPU可以拉成100%
回复 使用道具 举报
nobt
论坛元老   /  发表于:2019-10-17 15:57:42
5#



  1. /** 自定义函数开始 */
  2.                 function getFormulaFunction() {
  3.                     this.name = "GETFORMULA";
  4.                     this.maxArgs = 3;
  5.                     this.minArgs = 1;
  6.                 }
  7.                 getFormulaFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
  8.                 getFormulaFunction.prototype.acceptsReference = function (argIndex) {
  9.                     if(argIndex === 0 || argIndex === 1 || argIndex === 2){
  10.                         return true;
  11.                     }
  12.                     return false;
  13.                 }
  14.                 getFormulaFunction.prototype.isContextSensitive = function(){
  15.                     return true;
  16.                 }
  17.                 getFormulaFunction.prototype.evaluate = function (context,arg1,arg2,arg3) {
  18.                     debugger
  19.                     console.log(arg1.getRowCount()+",列:"+arg1.getColumnCount());
  20.                     var result = 1;
  21.                     if(arg1.getRowCount() > 1 || arg1.getColumnCount() > 1){
  22.                         debugger
  23.                         var sheet = spread.getActiveSheet();
  24.                         var selectedValue = [];
  25.                         for(var i=0;i<arg1.getRowCount();i++){
  26.                             for(var j=0;j<arg1.getColumnCount();j++){
  27.                                 var value = sheet.getValue(arg1.getRow()+i,arg1.getColumn()+j);
  28.                                 if(value){
  29.                                     selectedValue.push(value);
  30.                                 }
  31.                             }
  32.                         }
  33.                         var result = sum(selectedValue);
  34.                         sheet.setValue(10, arg2.getColumn(), result + "_b")
  35.                         sheet.setValue(arg3.getRow(), arg3.getColumn(), result + "_c")
  36.                         return result + "_a";
  37.                     }
  38.                     return "#VALUE!";
  39.                 };
  40.                 designer.wrapper.spread.getActiveSheet().addCustomFunction(new getFormulaFunction());
  41.                 GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETFORMULA", new getFormulaFunction());
  42.                 /** 自定义函数结束 */
复制代码
回复 使用道具 举报
nobt
论坛元老   /  发表于:2019-10-17 16:47:00
6#
function.rar (2.46 KB, 下载次数: 46)
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部