[英]Google sheet script, return range value is 3 cells off
I wrote this code with a trigger to send me emails upon a specific number of days remaining in the schedule. 我编写了此代码,并附带了触发器,以便在计划中剩余的特定天数时向我发送电子邮件。 Everything works fine, but the content of my email is always 3 rows off for the variables
fournir
and projet
. 一切正常,但对于变量
fournir
和projet
,我的电子邮件内容始终关闭3行。 I think that it's probably because of the getRange
associated with these variables but since I'm fairly new with scripting, I don't know how to fix it. 我认为这可能是由于与这些变量相关联的
getRange
,但是由于我对脚本尚不熟悉,所以我不知道如何解决它。
Thanks in advance 提前致谢
function checkValue()
{
var NOMBREDELIGNES = 3000;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange(3, 8, NOMBREDELIGNES); // ligne de départ, colonne, nombre de lignes
var values = range.getValues();
for (var row in values) {
for (var col in values[row]) {
var crissedevaleur = values[row][col];
if(crissedevaleur == 1 || crissedevaleur == 3 || crissedevaleur == 7) {
var projet = sheet.getRange(row,1).getValue();
var fournir = sheet.getRange(row,4).getValue();
MailApp.sendEmail("dufourlarouche@gotoast.ca","Rappel de votre compte en banque [" + projet + "]" ,"Échéance dans " + crissedevaleur + " jours pour \n\n" + fournir);
}
}
}
}
When you use range.getValues() in Google Apps Script, you get a double array. 在Google Apps脚本中使用range.getValues()时,将得到一个双精度数组。 When you loop through the array the rows start at 0 and count up.
当您遍历数组时,行从0开始并向上计数。
The row value corresponds to the row in the array, not the row on your sheet. 行值对应于数组中的行,而不是工作表中的行。 To fix this, you will need to simply add range.getRow() or 3 to the row you are getting the value of.
要解决此问题,您只需将range.getRow()或3添加到要获取其值的行。
Use: 采用:
var projet = sheet.getRange(row+range.getRow(),1).getValue();
var fournir = sheet.getRange(row+range.getRow(),4).getValue();
or 要么
var projet = sheet.getRange(row+3,1).getValue();
var fournir = sheet.getRange(row+3,4).getValue();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.