How to Import Google Contacts to Spreadsheet Using Script

Google provides very easy to use interface to manage Google contacts. You may need to share your contacts with someone else or to store them locally in file. That can be done with in-build export option within the Google contacts.  Right now Google Contacts export option is only available in older version. You will need to switch back to older version of Google contacts to use contacts export functionality. But if we want to automate contacts importing within some plugins or add-ons, we need to write script. In this article we are going to provide the way to import Google contacts to spreadsheet using script.Import Google Contacts

Spreadsheet can store small or large data organized within rows and columns in tabular form. They can used to process data. Manipulations, sorting, filtering, as well as built-in functions for finance and other operations make spreadsheets very powerful.

In this article we are going to import contacts from contacts group. So First create Contacts Group. Here is the way to create contact group for your mailing list.

Creating Contacts Group – For Creating Contacts group open Contacts from Gmail. Then Select contacts and assign them to label or group. For more information Read How to Create Google Contacts Group

Import Google Contacts to Spreadsheet

  1. To start working on spreadsheet, open Google Drive.
  2. In Google Drive, click on New button. Select Google Sheet >Blank Spreadsheet from drop-down.Create New SpreadSheet
  3. Name the Spreadsheet as we are going to import contacts in it.Edit Spreadsheet Name
  4. From Menu select Tools> Script Editor. Open Script Editor
  5. In opened Script Editor , Type the following Code.
function Importcontacts()
{ 
  var group  = ContactsApp.getContactGroup('BulkGroup'); // Fetches group by groupname 
  var contacts = group.getContacts();                    // Fetches contact list of group 
  var ss = SpreadsheetApp.getActiveSpreadsheet();        //Get currently Active sheets 
  var sheet = ss.getSheets()[0];                         //Get first from active sheets list 
  sheet.appendRow(['Full Name', 'Email Address']);// Creating Header
  for (var i in contacts) 
      {
         var fullname=contacts[i].getFullName();    // gets full name of contact 
         var emailid=contacts[i].getEmails();                     //get emailid of contact 
         for(i in emailid) 
           { 
      sheet.appendRow([fullname, emailid[i].getAddress()]);// append contact data to active sheet 
           } 
       } 
}

In above code the first line of function, “Bulkgroup” in green text is a the name of contacts Group. Replace “BulkGroup” with desired contacts group name from your google contacts.Code for Import

  • After pasting the above code in script editor, replace ‘Bulkgroup’.
  • You can also rename script file.Rename script file
  • Now code is written and script needs to be run for importing contacts to spreadsheet.
  • To run script Go to Menu>run>run function>ImportContacts.Run Script Function
  • When you will run the code Google may alert you about “App isn’t verified”. To continue click on advanced. It will show link to continue to unsafe. Click on that.App not verified
  • Google will also ask for permission to grant permission to this script to get access of the contracts. Grant the permission to start importing contacts.Grant Access permission
  • After script run gets completed, you can check spreadsheet for imported contacts.

Sharing is caring!

Leave a Reply