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 谷歌应用程序脚本onedit甚至不获取列标题_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 谷歌应用程序脚本onedit甚至不获取列标题

Google apps script 谷歌应用程序脚本onedit甚至不获取列标题,google-apps-script,google-sheets,Google Apps Script,Google Sheets,上面是我在工作表中运行的代码。现在,这个on edit事件应该从当前活动的单元格中获取列标题。然后使用if语句应该在timestamp列名中放入一个静态值,这样我就可以在工作表中放入时间戳。我真的很难调试这个,因为我不知道如何在谷歌脚本屏幕上调试编辑。所以我不知道代码有什么不对的地方。现在它什么也不做。浏览提供的代码令人困惑。(例如,editColumn在第6行中使用,但仅在第8行中声明,并且使用了timeStampColName但未在声明时提供值)。你能相应地格式化代码,看看是否有什么变化吗。

上面是我在工作表中运行的代码。现在,这个on edit事件应该从当前活动的单元格中获取列标题。然后使用if语句应该在timestamp列名中放入一个静态值,这样我就可以在工作表中放入时间戳。我真的很难调试这个,因为我不知道如何在谷歌脚本屏幕上调试编辑。所以我不知道代码有什么不对的地方。现在它什么也不做。

浏览提供的代码令人困惑。(例如,
editColumn
在第6行中使用,但仅在第8行中声明,并且使用了
timeStampColName
但未在声明时提供值)。你能相应地格式化代码,看看是否有什么变化吗。我使用的是静态引用,但现在我需要获取我正在编辑的单元格的列标题,以便在适当的单元格中生成时间戳。因此,我将if语句放在那里以获取我正在编辑的单元格的标题,然后尝试使用if语句声明timestampcolname。然后像以前一样运行脚本的其余部分。到目前为止,结果是相同的,没有应用时间戳。
function onEdit(event)
{ 
  var timezone = "GMT-6";
  var timestamp_format = "HH:mm:ss"; // Timestamp Format. 
  var sheet = event.source.getActiveSheet();//Name of the sheet where you want to run this script.
  var actRng = event.source.getActiveRange();
  var editColumn = actRng.getColumn();
  var index = actRng.getRowIndex();
  var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues();
  var dateCol = headers[0].indexOf(timeStampColName);
  var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1;
  var updateColName = sheet.getRange( 1, editColumn).getValue ();
  var timeStampColName = "null";

  if (updateColName == "PACK STARTED BY") {timeStampColName = "Pack Start";}

if (dateCol > -1 && index > 1 && editColumn == updateCol) { // only timestamp if 'Last Updated' header exists, but not in the header row itself!
    var cell = sheet.getRange(index, dateCol + 1);
    var date = Utilities.formatDate(new Date(), timezone, timestamp_format);
    cell.setValue(date);
  }
}