Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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应用程序脚本电子邮件查找中的空字段_Google Apps Script - Fatal编程技术网

Google apps script 如何修复Google应用程序脚本电子邮件查找中的空字段

Google apps script 如何修复Google应用程序脚本电子邮件查找中的空字段,google-apps-script,Google Apps Script,我正在建立一个电子表格rota系统。我在网上找到了一些适合我大多数需要的脚本 这是我正在使用的表(带有虚拟数据)—— 然而,在调整它以使用我想要的格式和布局时,我发现它不能很好地使用任何空单元格 我尝试过使用if语句,但它不喜欢它-语法错误(来自“e-mailaddress=”部分) 这是我用来发送电子邮件的当前代码。有一个单独的函数来查找电子邮件地址 // Send an email to the first person emailAddress=getEmai

我正在建立一个电子表格rota系统。我在网上找到了一些适合我大多数需要的脚本

这是我正在使用的表(带有虚拟数据)——

然而,在调整它以使用我想要的格式和布局时,我发现它不能很好地使用任何空单元格

我尝试过使用if语句,但它不喜欢它-语法错误(来自“e-mailaddress=”部分)

这是我用来发送电子邮件的当前代码。有一个单独的函数来查找电子邮件地址

        // Send an email to the first person

      emailAddress=getEmailFromName(row[1]) + "," +

                      getEmailFromName(row[2]) + "," +

                      getEmailFromName(row[3]) + "," +

                      getEmailFromName(row[4]);


        MailApp.sendEmail(emailAddress, subject, message);

//要使用此函数,请不要在第一列(A)或第(1)行中放置任何内容。
//将名称(即密钥或我们正在查找的内容)放在B列中。
//将我们想要返回的内容放在C列中。
var columnToSearch=1;//列B
//将活动工作表设置为我们的电子邮件查找
var ss1=SpreadsheetApp.getActiveSpreadsheet();
var sh1=ss1.getSheetByName(“EmailContactList”)
ss1.设置活动表(sh1);
var data=SpreadsheetApp.getActiveSheet().getDataRange().getValues();
var行=-1;
对于(变量i=0;i

我希望我的rota从第一列开始不一定是满的&如果它是空的,则跳过该列,只发送到找到匹配项的电子邮件地址。

假设电子邮件地址在第1列到第4列,其中一些可能是空的:

for (var x = 1; x < 5; x++) { // 5 because emails are till col4

    var emailAddress = []; // Start by collecting the non-blank emails in an array

    if (getEmailFromName(row[1]) != "") {

      emailAddress.push(getEmailFromName(row[x]))

    }

  }

  emailAddress = emailAddress.join();  // Join the array to get a comma separated string

  MailApp.sendEmail(emailAddress, subject, message);
for(var x=1;x<5;x++){//5,因为电子邮件在第4列
var emailAddress=[];//首先收集数组中的非空电子邮件
如果(getEmailFromName(第[1]行))!=“”){
emailAddress.push(getEmailFromName(第[x]行)))
}
}
emailAddress=emailAddress.join();//加入数组以获取逗号分隔的字符串
MailApp.sendmail(电子邮件地址、主题、消息);

您能分享一份工作表吗?是的,很抱歉。将编辑原始帖子。这很有效。只需将开场白IF语句中的(第[1]行)更改为(第[x]行)



  // to use this function, don’t put anything in the first column (A) or row (1).

  // Put the name (i.e. the key, or what we’re looking for) in column B.

  // Put what we want to return in column C. 



  var columnToSearch = 1; //column B



  // Set the active sheet to our email lookup

  var ss1 = SpreadsheetApp.getActiveSpreadsheet();

  var sh1 = ss1.getSheetByName("EmailContactList")

  ss1.setActiveSheet(sh1);



  var data = SpreadsheetApp.getActiveSheet().getDataRange().getValues();



  var line = -1;

  for( var i = 0; i < data.length; i++ ) {

    if( data[i][columnToSearch] == sKey ) {

      line = i;

      break;

    }

  }



  if( line != -1 ) {

    //do what you want with the data on "line"

    return data[line][2]; //value on column C of the matched line

  } else {

  return "";

  // if criteria is not found

  }

}
for (var x = 1; x < 5; x++) { // 5 because emails are till col4

    var emailAddress = []; // Start by collecting the non-blank emails in an array

    if (getEmailFromName(row[1]) != "") {

      emailAddress.push(getEmailFromName(row[x]))

    }

  }

  emailAddress = emailAddress.join();  // Join the array to get a comma separated string

  MailApp.sendEmail(emailAddress, subject, message);