google-apps-script - 优化空间?
问题描述
我的代码作为单个数组自定义函数可以正常工作,但是当我尝试运行时
Arrayformula(如果 A2:A = true, nextyear(A2:A),nextmonth(A2:A)
它不起作用,它说内部错误。
从我所看到的看起来可能是因为我的功能花费了太长时间?
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 中使用。通常最好构建一个自定义函数来完成整个公式的工作。
为什么?
自定义函数有 30 秒的执行时间限制,而内置函数没有此功能。
另一个限制是自定义函数不能使用 NOW()、TODAY()、RAND()、RANDBETWEEN() 等易失性函数作为参数。
有关的
推荐阅读
- python-3.x - 为什么将导入重命名为相同名称?
- javascript - 是否可以为流中的外部库声明这种类型?
- jdbc - 无法使用 JDBC 和 HSQLDB 从 sql 数组中获取数据
- python - 如何将集成机器学习模型保存在 .h5 和 json 中?
- python-3.x - 使用 asyncpg 读取 PostgreSQL 表
- python - 使用 python 的 sklearn 模块和自定义数据集
- google-cloud-firestore - SwiftUI、List、.onDelete(perform:) 和 Firestore
- azure-devops - 在 Azure DevOps 中使用 --set helm 覆盖列表值
- python - Python 33gb csv 文件数据集到 Pandas DataFrame
- escaping - 如何使用 MessageFormat.js 为“SelectFormat”转义“/”