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

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

问题描述

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

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

Arrayformula(if A2:A = true, nextyear(A2:A),nextmonth(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天全站免登陆