Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 如何在Google Sheets中为特定行设置日期戳?_Google Apps Script_Google Sheets_Timestamp - Fatal编程技术网

Google apps script 如何在Google Sheets中为特定行设置日期戳?

Google apps script 如何在Google Sheets中为特定行设置日期戳?,google-apps-script,google-sheets,timestamp,Google Apps Script,Google Sheets,Timestamp,我正在尝试设置一个GoogleSheets电子表格,当编辑某个特定单元格时,右边单元格中的日期将更新,以表明已进行了更改。在GoogleSheets论坛上,有人指示我来这里寻求最佳指导 脚本本身工作得很好。但是,我想将它限制在特定的单元格(或行,两者都可以)中,这样就不会在标题行中添加日期戳。我需要向脚本添加什么才能将其应用于特定的单元格/行 以下是我现在的脚本: function onEdit() { var s = SpreadsheetApp.getActiveSheet(); v

我正在尝试设置一个GoogleSheets电子表格,当编辑某个特定单元格时,右边单元格中的日期将更新,以表明已进行了更改。在GoogleSheets论坛上,有人指示我来这里寻求最佳指导

脚本本身工作得很好。但是,我想将它限制在特定的单元格(或行,两者都可以)中,这样就不会在标题行中添加日期戳。我需要向脚本添加什么才能将其应用于特定的单元格/行

以下是我现在的脚本:

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  var r = s.getActiveCell();
  if( r.getColumn() != 3 ) { //checks the column
    var row = r.getRow();
    var time = new Date();
    time = Utilities.formatDate(time, "GMT-07:00", "MM/dd/yy");
    SpreadsheetApp.getActiveSheet().getRange('C' + row.toString()).setValue(time);
  };
 }; 

假设我有一张有30行的工作表。我希望邮戳出现在第9行到第13行;15至18岁;从20到26。其他行都是标题,我希望能够在不使用日期戳填充相邻单元格的情况下更改其中的文本。如果可能的话,我将如何编辑脚本以在Google Sheets中实现这一点?谢谢

只需在列条件中添加更多条件即可

例如,对于第一个系列的两行:

  if( r.getColumn() != 3 && ((row>8 && row<14)||(row>14 && row<19))){ // continue with other AND and OR for all your conditions
它将自动匹配工作表的时区,即使您所在的国家有夏令时

var tz = Session.getScriptTimeZone();
var time = Utilities.formatDate(new Date(),tz, "MM/dd/yy");