Google表格自动时间戳

时间:2017-09-25 18:48:44

标签: google-sheets google-spreadsheet-api

我的脚本退出谷歌工作表。我不明白为什么第7行挂断了。

这是脚本

function onEdit(event)
{ 
  var timezone = "GMT-7";
  var timestamp_format = "MM-dd-yyyy HH:mm:ss";
  var updateColName = "Narrative";
  var timeStampColName = "Time Stamp";
  var sheet = event.source.getSheetByName('Narrative'); 


  var actRng = event.source.getActiveRange();
  var editColumn = actRng.getColumn();
  var index = actRng.getRowIndex();
  var headers = sheet.getRange(2, 2, 2, sheet.getLastColumn()).getValues();
  var dateCol = headers[0].indexOf(timeStampColName);
  var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1;
  if (dateCol > -1 && index > 1 && editColumn == updateCol) {
    var cell = sheet.getRange(index, dateCol + 1);
    var date = Utilities.formatDate(new Date(), timezone, timestamp_format);
    cell.setValue(date);
  }
}

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

是否更改了工作表的名称?

var sheet = event.source.getSheetByName('Narrative');