需要获得谷歌工作表仪表板的永久时间戳



我正在尝试为谷歌表单中的活动构建一个面板,为此,我有一个页面,学生可以在其中输入活动名称和状态:活动页面

我需要获得活动状态被修改的时间戳,这发生在另一个页面中:仪表板页面

在这里,我使用标志来锁定通过now((函数获取的时间和日期。问题是:每次页面更新时,我都会丢失时间戳。我如何才能永久获得它?

您可以使用应用程序脚本来实现您的目标:

  1. 使用onEdit
    触发器以检查某个单元格何时被手动更改
  2. 检查单元格是否来自列Status并获取行
  3. 根据Status的值在另一张表中写入时间戳

例如:

function onEdit(event){
var editedSheet = event.source.getActiveSheet();
var eRange = event.range;
// If the name is Activities and the column edited is A
if (editedSheet.getName() == "Activities" && eRange.getColumn() == 1){
var sprsheet = SpreadsheetApp.getActiveSpreadsheet();
var dashboard = sprsheet.getSheetByName("Dashboard");
var dshbValues = dashboard.getRange("B1:L1").getValues(); //Values in Dashboard
//Compare the value introduced with the Values in Dashboard   
for (var i = 0; i < dshbValues[0].length; i++){
//If they coincide, write the timestamp in the row edited, correspondent column
if (eRange.getValue() == dshbValues[0][i]){
var timestamp = new Date();
dashboard.getRange(eRange.getRow(), i + 2).setValue(timestamp);
}
}
}
}

考虑到第一次需要手动运行脚本才能授予所需的权限。此外,出于一致性的目的,活动列C和仪表板列A中的值需要按相同的顺序排列。

参考文献:

  • 范围类
  • 获取值
  • 设置值
  • 日期((

最新更新