簡體   English   中英

谷歌表格時間戳通過應用程序腳本

[英]Google sheets timestamp via apps script

首先讓我說我對谷歌應用程序腳本和 JavaScript 非常陌生。 我正在編寫一個腳本,該腳本將在第 13 列從下拉列表中將其狀態更改為“已接受”或“進行中”時添加時間戳,然后根據選擇的狀態將時間戳放入第 24 列或 25 列。 它還檢查目標單元格中是否已有文本。

我的問題是第一部分工作正常,選擇“接受”將完全按照它應該輸入的時間戳,但是當我 select“進行中”時沒有任何反應。 我認為這可能是由於我的 {} 括號放置,但我自己無法弄清楚。 輸入將不勝感激。

function onEdit(e) {  

  addTimestamp(e);

  
}

function addTimestamp(e){
  //variables
  var startRow = 3;
  var currentDate = new Date();
  var targetColumn = 13;
  var ws = "Call Log";
  var ss = "Copy of Project Worksheets (for testing)";
  //get modified row and column
  var row = e.range.getRow();  //value for row
  var col = e.range.getColumn(); //value for the column
  
    if(col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws) { 
// Checks the name of the sheet you are working on, in this case its Call log.
      if(e.source.getActiveSheet().getRange(row,13).getValue() =="Accepted"){
        if(e.source.getActiveSheet().getRange(row,24).getValue() =="")
          e.source.getActiveSheet().getRange(row,24).setValue(currentDate);}
        
      if (e.source.getActivesheet().getRange(row,13).getValue() =="In Progress"){
        if(e.source.getActiveSheet().getRange(row,25).getValue() =="")
          e.source.getActiveSheet().getRange(row,25).setValue(currentDate);}
  } // END IF check column, row, and worksheet name
 } // END IF function addTimestamp```

您在getActivesheet()中有拼寫錯誤

改變:

if (e.source.getActivesheet().getRange(row,13).getValue() =="In Progress")

if (e.source.getActiveSheet().getRange(row,13).getValue() =="In Progress")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM