我有一个范围为A2:A
的电子邮件(该范围内的多个单元格在一个单元格中有2或3封电子邮件)。
另外,我有一个单元格C3
,其中有一封电子邮件。该C3
单元中可能包含1或2封电子邮件(如下面的屏幕截图所示,请查看E3
单元)。
我想检查来自C3
单元格的电子邮件(或任何电子邮件)是否在该电子邮件范围A2:A
中。
问题在于,多个单元格中有2到3封电子邮件,我不知道如何在一个单元格中循环浏览每封电子邮件。
我当时正在考虑创建一个Google Apps脚本,该脚本检查一个单元格是否有2封电子邮件,它将每个电子邮件存储在该单元格中并遍历整个电子邮件范围。但是可能有更简单的方法。
希望您能理解我的意思:)非常感谢!
答案 0 :(得分:1)
尝试一下:
function findEmails() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Sheet1');
var vA=sh.getRange(2,1,sh.getLastRow()-1,sh.getLastColumn()).getValues();
var list=sh.getRange(1,1,sh.getLastRow()-1,1).getValues().map(function(r){return r[0]}).filter(function(e){return e;});
var found=[];//stores the email found and the cell it came from in A1 notation
for(var i=0;i<vA.length;i++) {
if(vA[i][2]) {
var emA=vA[i][2].toString().split('\n');emA.forEach(function(e,j){var idx=list.indexOf(e);if(idx>-1){found.push({email:e,location:sh.getRange(i+1,3).getA1Notation()});}});
}
if(vA[i][4]) {
var emA=vA[i][4].toString().split('\n');emA.forEach(function(e,j){var idx=list.indexOf(e);if(idx>-1){found.push({email:e,location:sh.getRange(i+1,5).getA1Notation()});}});
}
}
Logger.log(found);
}
这是在我的示例中找到的内容:
[{location=C1, email=email4@gmail.com},
{location=E1, email=email7@gmail.com},
{location=E1, email=email13@gmail.com}]
这些电子邮件与您使用我自己的数据时不会相同。但是您可以通过查看代码来了解如何执行此操作。我确实希望电子邮件将始终以'\ n'(换行符)分隔;