优化空间? [英] Room For Optimization?

本文介绍了优化空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码可以作为单个数组自定义函数正常运行,但是当我尝试运行时

My code works fine as a single array custom function but when I try to run

Arrayformula(如果A2:A = true,则下一年(A2:A),下个月(A2:A)

Arrayformula(if A2:A = true, nextyear(A2:A),nextmonth(A2:A)

它不起作用,显示内部错误.

It doesn't work, it says internal error.

从我所看到的看起来可能是因为我的函数花费的时间太长了?

From what I've seen looks like it could be because my function is taking too long?

function NextMonth(input) {

   if(input.map) {
    return input.map(NextMonth);}

  else {
  var month = Utilities.formatDate(new Date(input), "GMT+0","MM")-1;
  var day = Utilities.formatDate(new Date(input), "GMT+0","dd");
  var year = Utilities.formatDate(new Date(input), "GMT+0","yyyy");

  var output = new Date(year,month,day,0,0,0,0);
  var now = new Date();

  while (output < new Date()) {
  var month = Utilities.formatDate(new Date(output), "GMT+0","MM")-1+1;
  var day = Utilities.formatDate(new Date(output), "GMT+0","dd");
  var year = Utilities.formatDate(new Date(output), "GMT+0","yyyy");
  var output = new Date(year,month,day,0,0,0,0);

  }

  return (output)
  }
} 

推荐答案

自定义函数不能以与内置函数相同的方式在ARRAYFORMULAS中使用.通常,最好构建一个自定义函数来完成整个公式.

Custom functions can't be used in ARRAYFORMULAS in the same way that built-in functions could be used. Usually it's better to build a custom function that does what the whole formula does.

为什么?

自定义功能的执行时间限制为30秒,而内置功能则没有此功能.

Custom functions have a 30 seconds execution time limit while built-in functions doesn't have this function.

另一个限制是帽子自定义函数不能使用诸如NOW(),TODAY(),RAND(),RANDBETWEEN()等易失函数作为参数.

Another limitation is hat custom functions can't use volatile functions like NOW(), TODAY(), RAND(), RANDBETWEEN() and others as arguments.

相关

这篇关于优化空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆