我有一个不断收到此错误的Apps脚本.通过通知邮件判断,看起来时间限制是5分钟.有谁知道是否有办法延长这个时间限制?或者是否有办法再次调用Apps脚本,它从它停止的地方开始提取?任何帮助表示赞赏.
我的谷歌应用程序脚本正在迭代用户的谷歌驱动器文件和复制,有时将文件移动到其他文件夹.该脚本始终在5分钟后停止,日志中没有错误消息.
我在一次运行中排序数十或有时数千个文件.
有任何设置或解决方法吗?
第一次发帖,长时间阅读:)
我刚刚编写了我的第一个谷歌应用程序脚本来整理来自14个电子表格的信息,每张表格包含2-30个工作表到一个报告电子表格中.
该脚本运行得很漂亮,它检查单个列的数据,如果找到,则抓取电子表格名称,工作表名称,行的第一列数据和检查列中的数据,并将其作为数据子数组添加到数组中.
然后,它计算子数组数组的区域,并将数据写入报告文件(运行脚本的位置).
我唯一的问题是它需要大约2分钟的脚本才能运行.
我想知道我的方法是否效率低下,并希望有人可以查看脚本并告诉我是否犯了一些错误?
开始:
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function getFaults() {
/** opens each spreadsheet for Liddon and examines the "Report/Replace" column "F"
if there is data there then get the
[Sheetname], [fault area (column "A" row relative to the "F" field found)] and the ["F" field …Run Code Online (Sandbox Code Playgroud) [编辑以包含TJ Crowder建议的最小可重现示例。]
我正在使用 Google Apps 脚本开发一个简单的函数,该函数应该将日期或错误字符串发布到电子表格的列中。该列已具有拒绝任何非有效日期值的数据验证规则。这一切都很好。
我的问题是这样的:
我尝试使用 try...catch 块来优雅地处理错误,并在值未通过数据验证时仅记录错误消息。try...catch 似乎根本不起作用。相反,脚本会抛出错误并中断,并且日志显示为空。
这是带有新代码的更新屏幕截图(抱歉,Sourabh Choraria,覆盖了您的更新)。令人惊讶的是,GAS 突出显示了错误发生位置上方的一行。

作为一点背景知识,此脚本获取存储在列中的各种其他电子表格的 ID,获取每个电子表格的最后更新时间戳,并将结果发布到结果列中。
这是我使用的代码。
function trackDocUpdates() {
//Set the global variables
var ss = SpreadsheetApp.getActive();
var residentSheet = ss.getSheetByName("Resident Documents");
var activeRange = residentSheet.getDataRange();
var numRows = activeRange.getNumRows();
var lastRevision = "No value yet.";
//Loop through the rows of data to get the last updated timestamp of each document
//The first data row is the 5th row …Run Code Online (Sandbox Code Playgroud) javascript validation try-catch google-sheets google-apps-script
我想从我的工作表中获取一个范围。按照最佳实践中的建议,我试图获取一个数组并对其进行操作,但我很困惑:
const ss = Spreadsheet.getActive(),
sh = ss.getSheetByName("Sheet1"),
rg = sh.getRange("A1:C1"),//has 1,2,3
values = rg.getValues();
console.log(values);
Run Code Online (Sandbox Code Playgroud)
日志显示
[[1,2,3]]
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我得到了所有三个元素。但是,当我记录数组(array.length)的长度时,它只是 1(而不是 3)。当我使用.indexOfor测试元素是否存在时.includes,它显示 -1 或false。
const ss = Spreadsheet.getActive(),
sh = ss.getSheetByName("Sheet1"),
rg = sh.getRange("A1:C1"),//has 1,2,3
values = rg.getValues();
console.log(values);
Run Code Online (Sandbox Code Playgroud)
为什么?
我有同样的问题setValues()。
rg.setValues([1,2,3]);//throws error
Run Code Online (Sandbox Code Playgroud)
错误是
“参数 (number[]) 与 SpreadsheetApp.Range.setValues 的方法签名不匹配。”
我的具体问题是:究竟getValues() 返回什么?它是一种特殊的数组吗?
arrays multidimensional-array google-sheets google-apps-script