【发布时间】:2021-02-02 20:05:40
【问题描述】:
我正在使用 google 电子表格和 Apps 脚本来收集一些财务数据,其中一个功能需要一些时间,因为它需要处理大量信息。
因此,谷歌向我展示了超过最大执行时间,但即使有一个 for 循环在每个循环上写入文件,它也不会在函数完成之前执行它。
有人可以告诉我在执行时如何编写电子表格吗?
谢谢。
在这里留下一个示例脚本。
function myFunction() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var rangeSheet = activeSheet.getRange(1, 1, activeSheet.getLastRow() - 1, 1).getValues();
// after cleared out i have an array of values so i do:
rangeSheet.forEach(async (el, idx) => {
let result = await anotherFunction(el) // <--- this is the function taking around 2 minutes to complete
sheet.getRange(`$B${idx + 1}`).setValue(`${result}
})
}
【问题讨论】:
-
能否提供
anotherFunction相关的代码?
标签: javascript google-apps-script google-sheets