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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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电子表格附加了一个带有时间戳的数组_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script Google电子表格附加了一个带有时间戳的数组

Google apps script Google电子表格附加了一个带有时间戳的数组,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我找到了这段代码 我修改了它以更好地满足我的需要。我把它用作调度日志。在deliveries选项卡中,当我将最后一列更改为delivered时,它会将其复制到delivered选项卡减去最后一列。并删除旧的行。它完成了任务,但我想对其进行编辑,以便在复制的数据中添加一个包含日期戳的新列。这样,当我查看“已交付”选项卡时,它将显示交付日期 我试了又试,但我的JavaScript知识还不够好。我在这里和其他网站上搜索了几个小时,寻找一些能让我朝正确方向前进的东西,但毫无结果 /** * M

我找到了这段代码

我修改了它以更好地满足我的需要。我把它用作调度日志。在deliveries选项卡中,当我将最后一列更改为delivered时,它会将其复制到delivered选项卡减去最后一列。并删除旧的行。它完成了任务,但我想对其进行编辑,以便在复制的数据中添加一个包含日期戳的新列。这样,当我查看“已交付”选项卡时,它将显示交付日期

我试了又试,但我的JavaScript知识还不够好。我在这里和其他网站上搜索了几个小时,寻找一些能让我朝正确方向前进的东西,但毫无结果

    /**
 * Moves row of data to another spreadsheet based on criteria in column 6 to sheet with same name as the value in column 4.
*/

function onEdit(e) {
  // see Sheet event objects docs
  // https://developers.google.com/apps-script/guides/triggers/events#google_sheets_events
  var ss = e.source;
  var s = e.range.getSheet();
  var r = e.range;

  // to let you modify where the action and move columns are in the form responses sheet
  var actionCol = s.getLastColumn();
  var nameCol = s.getLastColumn();

  // Get the row and column of the active cell.
  var rowIndex = r.getRowIndex();
  var colIndex = r.getColumnIndex();

  // Get the number of columns in the active sheet.
  // -1 to drop our action/status column
  var colNumber = s.getLastColumn()-1;

  // if our action/status col is changed to ok do stuff
  if (colIndex == actionCol) {
    // get our target sheet name - in this example we are using the priority column
    var targetSheet = s.getRange(rowIndex, nameCol).getValue();
    // if the sheet exists do more stuff
    if (ss.getSheetByName(targetSheet)) { 
      // set our target sheet and target range
      var targetSheet = ss.getSheetByName(targetSheet);
      var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
      // get our source range/row
      var sourceRange = s.getRange(rowIndex, 1, 1, colNumber);

      // new sheets says: 'Cannot cut from form data. Use copy instead.' 
      sourceRange.copyTo(targetRange);
      // ..but we can still delete the row after
      s.deleteRow(rowIndex);
      // or you might want to keep but note move e.g. r.setValue("moved");
    }
  }
}
你应该使用


代码应该在copyTo()之后,并且需要时间戳的标题才能工作

使用“GMT”不是一个好主意,因为许多国家使用夏令时,结果将是一年6个月的错误。。。他最好的解决方案是使用原生电子表格方法@Sergeinsas cool不知道,谢谢。更新了你的建议
var timezone = ss.getSpreadsheetTimeZone();
var timestamp = Utilities.formatDate(new Date(), timezone, "yyyy-MM-dd HH:mm:ss");
var timecell = targetSheet.getRange(targetSheet.getLastRow(), targetSheet.getLastColumn(), 1, 1);
timecell.setValue(timestamp);