简体   繁体   English

Google表格脚本,返回范围值关闭了3个单元格

[英]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 . 一切正常,但对于变量fournirprojet ,我的电子邮件内容始终关闭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.

相关问题 用脚本替换受保护范围内的用户(Google Sheet) - Replace user in a protected range by script (Google Sheet) 如何通过谷歌表格脚本 email 一系列数据? - How to email a range of data via google sheet script? 通过电子邮件发送Google表格单元格和格式 - Email Google Sheet cells and format Google Sheet Email 脚本到 email 在不同单元格中编辑的行的多个单元格 - Google Sheet Email script to email multiple cells of row that was edited in a different cell 使用VBA根据日期范围将单元导出到电子邮件 - Export Cells to Email based off range of dates using VBA 如何在谷歌表单脚本编辑器中设置 var 主题以返回其所连接的表单/工作表中指定字段的值? - How can I set the var subject in google forms script editor to return the values of specified fields in the form/sheet its is connected to? 工作表中的Google App脚本分组数据以电子邮件形式发送 - Google App Script Grouping data in sheet to email 使用Google表格中的脚本/宏共享表格 - Sharing a sheet using script/macros in Google Sheets 如何在Google工作表中以正确的格式邮寄单元格范围? - How do I mail cell range with proper format in google sheet? Google Apps 脚本 - 更新 Google 工作表中的行时 Email - Google Apps Script - Email when row in Google sheet is updated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM