繁体   English   中英

Google Apps脚本中的“找不到功能”对象中的偏移量

[英]Google Apps Script “cannot find function” offset in object

对以下问题有帮助吗??? 应用程序脚本/ javascript相当新,不胜感激的任何帮助或指导。

TypeError:在对象Timestamp中找不到函数偏移量,(然后继续在红色警告横幅中列出列标题。

function uiSendLogEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var data = sheet.getDataRange().getValues();
  data = data.offset(1,0,data.getNumRows())-1;


// For Loop

for ( var i = 0; i < data.length; i++ ) {
var row = data[i];
var approved = row[5];
var sentEmail = row[6];
var snapshot = row[3];

//if stmt in For Loop
if ( approved != "Yes" ) {              
  data[i][5] = "Yes";
  data.getDataRange().setValues(data);
      }// if stmt end curly 
else if ( approved == "Yes" && sentEmail != "Yes" ) {
  data[i][6] = "Yes";
  data.getDataRange().setValues(data);
  GmailApp.sendEmail("email@email.com", "subject", "body" + "whatever " + snapshot);
}//else if end curly
else {
return;
}//else stmt end curly

}// for loop end curly


 }

我做了一些基本的调整,希望可以将您指向正确的方向(并且感谢@AdamL的.shift()方法-比以前的方法要好得多:)):

function uiSendLogEmail() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var data = sheet.getDataRange().getValues();

  // Move the values down
  data.shift();

  // For Loop
  for ( var i = 0; i < data.length; i++ ) {
    var row = data[i];
    var approved = row[5];
    var sentEmail = row[6];
    var snapshot = row[3];

    // Here we set a range equal to the data range offset by 1 + our current
    // position in the loop (cycling through rows), and then get the A1 notation
    // of the first row, which we use to get that particular range and prep 
    // it for adding values
    var rng = sheet.getDataRange().offset(i+1,0,1).getA1Notation();
    myRange = sheet.getRange(rng);

    //if stmt in For Loop
    if ( approved != "Yes" ) {
      // Here we can just work with the row element itself
      row[5] = "Yes";
      // Because setValues expects a two dimensional array, 
      // we wrap our row in brackets to effectively convert it to one
      myRange.setValues([row]);
    }  // if stmt end curly 
    else if ( approved == "Yes" && sentEmail != "Yes" ) {
      // Same here as above
      row[6] = "Yes";
      myRange.setValues([row]);
      GmailApp.sendEmail("email@email.com", "subject", "body" + "whatever " + snapshot);
    }
    else {
      return;
    }
  }

我认为您想删除第一行数据(标题); 因此,请尝试替换:

data = data.offset(1,0,data.getNumRows())-1;

data.shift();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM