【问题标题】:Exporting from Google Sheets to Google Contacts从 Google 表格导出到 Google 通讯录
【发布时间】:2021-08-02 20:04:16
【问题描述】:

我正在尝试使用电子表格和脚本添加联系人。

到目前为止,我能够从这个用户那里复制脚本:How to sync google sheets database with google contacts

  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var sheet = ss.getSheetByName('Respostas ao formulário 1')
  var headerRows = 1;
  var MaxRow = sheet.getLastRow();
  var dataRange = sheet.getDataRange();
  var data = dataRange.getValues();     
  data.splice(0, headerRows);           

  function addContact() {
    for (var i = 0; i < data.length; i++) {
      var row = data[i];
      var firstName = row[1];
      var lastName = row[2];
      var email = row[3];
      var phone = row[4];
      var group = row[5];
      var job = row[6];
      var address2 = row[7];
         
      contact = ContactsApp.createContact(firstName, lastName, email);
      contact.addPhone(ContactsApp.Field.MOBILE_PHONE, phone);
      
      contact.setNotes(address2)
      contact.addCompany('', job)
      
      var group = ContactsApp.getContactGroup("System Group: My Contacts");
      group.addContact(contact);
   
    }

  }

效果很好,但我不知道如何添加年龄或自动为联系人添加标签。任何帮助都会很棒

【问题讨论】:

    标签: google-sheets google-contacts-api


    【解决方案1】:

    您需要创建a custom field。在您的代码中,如果您添加此行,我认为您将获得所需的内容:

    contact.addCustomField("Age", '26');
    

    【讨论】:

    • 谢谢,成功了!我算法使用 Nico 的答案来获取年龄,结果是这样的: var Age = row [7]; contact.addCustomField("Idade", Age);
    【解决方案2】:

    尝试添加“var age = row[8];”在“var address2 = row[7]; “或任何你想要的地方。如果你把它放在其他地方,你必须调整数字。

    希望能帮到你!

    【讨论】:

    • 谢谢,它成功了,我已经使用 PGSystemTester 的答案来做对了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-30
    • 2013-01-04
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    相关资源
    最近更新 更多