通过Google Spreadsheet创建联系人组 [英] Create a Contact Group via Google Spreadsheet
本文介绍了通过Google Spreadsheet创建联系人组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从Google表单创建电子邮件通讯组列表。然后,我想将个人放在特定的联系人组中。这是我到目前为止已编译的代码。请帮忙。
I am trying to create an email distribution list from a Google form. I then want to place the individuals in a particular contact group. Here is the code I've compiled thus far. Please help. Thank you in advance.
function addContact() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 3;
var numRows = 10; // I want the rows to be infinite
var dataRange = sheet.getRange(startRow, 2, numRows, 10)
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var firstName = row[1];
var lastName = row[2];
var emailAdd = row[3];
}
// The code below creates a new contact and adds it to the "Work Friends" contact group
var contact = ContactsApp.createContact(firstName, lastName, emailAdd);
var group = ContactsApp.getContactGroup('Work Friends');
group.addContact(contact);
}
推荐答案
您很近,只需要一些调整。
You were close, just needed some tweaking. See comments in-line, explaining the changes.
function addContact() {
var sheet = SpreadsheetApp.getActiveSheet();
// var startRow = 3; // This implies you have two header rows...
var headerRows = 2; // Number of header rows to skip
// var numRows = 10; // I want the rows to be infinite (so use getDataRange)
var dataRange = sheet.getDataRange(); // Range containing all non-blank rows & cols
var data = dataRange.getValues(); // Read all data
data.splice(0,headerRows); // Remove header rows
for (i =0; i<data.length; i++) { // Avoid using for..in with arrays
var row = data[i];
var firstName = row[1];
var lastName = row[2];
var emailAdd = row[3];
// Do this IN the loop vvv
// The code below creates a new contact and adds it to the "Work Friends" contact group
var contact = ContactsApp.createContact(firstName, lastName, emailAdd);
var group = ContactsApp.getContactGroup('Work Friends');
debugger; // Pause if running in debugger, to examine state
group.addContact(contact);
}
}
这篇关于通过Google Spreadsheet创建联系人组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文