我正在创建一个Google工作表,其中有多个用户需要以不同的时间间隔输入数据。每次他们输入数据时,都会有一个自动时间戳记来记录输入日期和时间的数据。我已将以下脚本用于时间戳。我已经保护了时间戳范围/列,因此以后没人可以对其进行更改。现在,在这种情况下,当用户更新任务时,时间戳不会自动更新。但是,当我删除保护时,时间戳运行良好。有人可以帮忙我如何保存时间戳,也请确保没有人可以编辑它。
时间戳功能脚本
onEdit(event) {
var timezone = "IST";
var timestamp_format = "MM-dd-yyyy HH:mm"; // Timestamp Format
var date = Utilities.formatDate(new Date(), timezone, timestamp_format);
var range = event.range; // this will be the last cell edited
var column = range.getColumn(); // use this to check the cell edited was in a relevant column
var rangeValue = range.getValue(); // use this to check something was actually entered into the last cell edited
var newRange = range.offset(0,1); // this is one cell to the right of the last cell edited
if ((column == 10|| column == 12|| column == 16|| column == 18|| column == 20|| column == 22|| column == 26|| column == 30|| column == 32|| column == 36|| column == 40|| column == 44) && rangeValue) { //if the last cell edited was in a relevant column, and there is a value in it
newRange.setValue(date);
} else if ((column == 10|| column == 12|| column == 16|| column == 18|| column == 20|| column == 22|| column == 26|| column == 30|| column == 32|| column == 36|| column == 40|| column == 44) && !rangeValue) { // there was no question or no response, so make sure there is no timestamp
newRange.setValue("");
}
}
工作表一览:
onEdit
installable触发器为什么?