我已经写了'Google脚本'以使用ContactsApp.getContactsByName
函数提取'电子邮件地址'。我下面提到的脚本正在运行,但在“ Google表格”的B列中未提供任何输出。
function test2() {
var s = SpreadsheetApp.getActiveSheet();
var cell = s.getRange('a1');
for (var x = 1; x <= 15; x++) {
var r = s.getRange(x,1);
var b = r.getValue()
if(b)
var nextCell = r.offset(0, 1);
nextCell.setValue(ContactsApp.getContactsByName[b]);
}
}
此后,我试图在代码的最后一行进行这些更改,并引发错误消息:-
更改1)
nextCell.setValue(ContactsApp.getContactsByName[b].getEmails());
更改2)
nextCell.setValue(ContactsApp.getContactsByName[b].getAddresses());
更改3)
nextCell.setValue(ContactsApp.getContactsByName[b].getEmails().getAddresses());
我是否可以请您提供正确的脚本帮助我?
关于,阿洛
如果联系人具有任何关联的电子邮件地址,则getEmails()方法将返回一个数组。您需要在单个数组项目上调用getAddress()以获得实际的电子邮件值。
这里是一个简单的例子:
var contacts = ContactsApp.getContactsByName("name here");
var email = contacts[0].getEmails()[0].getAddress();
Logger.log(email);