我完全不愿意为Google表格编写脚本。
我正在尝试编写一个脚本,该脚本将在从表单(而不是Google表单)插入Google工作表的行(第23列)中插入时间戳记;这是其他一些供应商将数据发送到工作表并且不会传递时间戳记)。
我一直在尝试从示例中编写脚本,但似乎无法使其正常工作。到目前为止,我的脚本如下:
function setUpTrigger() {
ScriptApp.newTrigger('timestamp')
.forSpreadsheet('spreadsheet_id_goes_here')
.onChange()
.create();
}
function timestamp(e){
if (e.changeType == 'INSERT_ROW'){
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(e.range.getRow(), 23).setValue(new Date());
}
}
任何帮助是极大的赞赏
该onChange
事件对象e
不包含关键range
。它不提供range
直接有关的信息。
在大多数情况下onChange
,特别是在您的情况下,更改类型为INSERT_ROW
,activeRange
表示插入的当前行。
function timestamp(e){
if (e.changeType == 'INSERT_ROW'){
const sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sh.getRange(sh.getActiveRange().getRow(), 23).setValue(new Date());
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句