blogtng:2010-06-15:google_apps_script_transferring_name_list_in_google_spread_sheet_to_google_contacts
google APPs script: transferring name list in google spread sheet to google contacts.
A bit for the convenience of organizing a course:
1. Student registration by google Forms
2. Using the automatically generated name, email address, units, sort each student to a class and store them in google contacts. google APPs script, javascripting
First part is more or less interactive, and second part code is as shown below.
//made on 100615 kota Miura // for sorting student list in Google spread sheet (collected by forms), // storing contacts in google contacts and also associate with each class. // function storeNamesInContacts() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var studentDataRange = sheet.getRange("A2:L29"); // For every row of student data, generate an student object. var studentObjects = getRowsData(sheet, studentDataRange); //right hand side is a custom functon in the tutorial var thirdst = studentObjects[2]; var gp1 = ContactsApp.findContactGroup("BasicCourse201006a"); if (gp1 == null) { var gp1 = ContactsApp.createContactGroup("BasicCourse201006a"); } var gp2 = ContactsApp.findContactGroup("BasicCourse201006b"); if (gp2 == null) { var gp2 = ContactsApp.createContactGroup("BasicCourse201006b"); } for (i=0; i<studentObjects.length; i++){ if ((studentObjects[i].course == 1) || (studentObjects[i].course == 2)) { nc = ContactsApp.createContact(FirstNameFrom(studentObjects[i].name), LastNameFrom(studentObjects[i].name), studentObjects[i].email); if (studentObjects[i].course == 1) nc.addToGroup(gp1); if (studentObjects[i].course == 2) nc.addToGroup(gp2); stringtodisp = "name "+ nc.getFullName()+"\n email "+ nc.getEmailAddresses()[0] + " course =" + studentObjects[i].course; //Browser.msgBox(stringtodisp); } } } function FirstNameFrom(fullname) { var key = ""; var upperCase = false; for (var i = 0; i < fullname.length; ++i) { var letter = fullname[i]; if (letter == " " && key.length > 0) { i = fullname.length; } else { key += letter; } } return key; } function LastNameFrom(fullname) { var key = ""; var laststarts = false; for (var i = 0; i < fullname.length; ++i) { var letter = fullname[i]; if (letter == " ") { laststarts = true; } else { if (laststarts ){ key += letter; } } } return key; }
At the bottom of above script, “Library” in the link below should be copied and pasted in the same file. http://www.google.com/google-d-s/scripts/reading_spreadsheet_data.html
blogtng/2010-06-15/google_apps_script_transferring_name_list_in_google_spread_sheet_to_google_contacts.txt · Last modified: 2016/05/24 12:46 by 127.0.0.1