优化空间? [英] 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.
相关
- 在 ARRAYFORMULA 中使用自定义 MD5 公式
- 如何在 ARRAYFORMULA 中为一系列单元格使用自定义函数?
- 执行自定义函数的内部错误"仅在使用该函数的多个单元格之一中
- 如何在 ArrayFormula 中使用自定义函数
这篇关于优化空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!