Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 如何将google sheets列中的值与数组进行比较,并根据列数据发送到特定电子邮件,以及向特定用户发送电子邮件_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 如何将google sheets列中的值与数组进行比较,并根据列数据发送到特定电子邮件,以及向特定用户发送电子邮件

Google apps script 如何将google sheets列中的值与数组进行比较,并根据列数据发送到特定电子邮件,以及向特定用户发送电子邮件,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我正在使我的谷歌工作表自动发送电子邮件,但我不知道如何将变量数组与谷歌工作表中的列进行比较。当我将数组放入“IF”语句中时,我会不断得到返回的所有值,而不仅仅是数组中的值。 我希望我的代码只显示gEnglish变量中的数据,而是显示所有数据。我还想知道如何才能根据地区向用户发送电子邮件 函数sendEmails(){ SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“主”).activate(); var ss=SpreadsheetAp

我正在使我的谷歌工作表自动发送电子邮件,但我不知道如何将变量数组与谷歌工作表中的列进行比较。当我将数组放入“IF”语句中时,我会不断得到返回的所有值,而不仅仅是数组中的值。 我希望我的代码只显示gEnglish变量中的数据,而是显示所有数据。我还想知道如何才能根据地区向用户发送电子邮件

函数sendEmails(){ SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“主”).activate(); var ss=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var lr=ss.getLastRow(); var decisionOne=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“模板”).getRange(1,1).getValue(); var decisionTWO=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“模板”).getRange(2,1).getValue(); var decisionThree=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“模板”).getRange(3,1).getValue(); var decisionFour=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“模板”).getRange(5,1).getValue(); var decisionFive=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“模板”).getRange(4,1).getValue(); var gEnglish=[“IT”、“US”、“GB”、“UK”]; var gSpanish=[“SP”]; var user1=[“JP”、“SK”、“IND”、“RU”]; var user2=[gEnglish,“UK”]; var user3=[gSpanish,“BR”,“PT”]; var user4=[“FR”、“DE”、“IT”]; 对于(变量i=2;变量:
.getValue()
返回单元格的数据,而不是数组。因此,不需要使用
区域[i]
引用数据

更多信息: 假设您在单元格
C1
中有值“Hello World”。要获取此值,可以使用
Range
对象的
getValue()
getValues()
方法

如果运行以下代码:

let c = SpreadsheetApp.getActiveSpreadsheet()
                      .getSheetByName(sheetName)
                      .getRange("C1");

console.log(c.getValue());
console.log(c.getValues());
执行日志将显示以下内容:

Oct 26, 2020, 11:42:39 AM   Debug   Hello World
Oct 26, 2020, 11:42:39 AM   Debug   [ 'Hello World' ]
执行相同操作,但正在访问元素[0]:

let c = SpreadsheetApp.getActiveSpreadsheet()
                      .getSheetByName(sheetName)
                      .getRange("C1");

console.log(c.getValue()[0]);
console.log(c.getValues()[0]);
将在执行日志中显示以下内容:

Oct 26, 2020, 11:44:39 AM   Debug   H
Oct 26, 2020, 11:44:39 AM   Debug   Hello World
修正: 更改以下行:

if (gEnglish.includes(region[i])) {
  //...
}
致:

我希望这对你有帮助

参考资料:

非常感谢!您的回答非常有帮助,解决了我的一个主要问题!我想知道我是否也必须在包含我的数组的var=user之前放置一个for循环,因为它的迭代性不好?例如var user2=[gEnglish,“UK”];不起作用,因为我里面有gEnglish很乐意帮忙!我不是100%确定你的意思,但是如果你试图设置
var user2=[“IT”、“US”、“GB”、“UK”、“UK]
你可以做
var user2=[gEnglish,“UK”].flat()
@hotsrriacha同样,出于文档目的,如果可以,请接受答案(✓) 这对你很有帮助——它还可以帮助将来遇到同样问题的其他人找到解决方案:)
if (gEnglish.includes(region)) {
  // ...
}