可以帮助解决以下问题吗???应用程序脚本/ 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
}
答案 0 :(得分:1)
我做了一些基本的调整,希望能指出你正确的方向(并且感谢@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;
}
}
答案 1 :(得分:0)
我认为你想要删除第一行数据(标题);所以,如果是这种情况,请尝试替换:
data = data.offset(1,0,data.getNumRows())-1;
与
data.shift();