Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions mashups/sheets2calendar.gs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,38 @@
*/
function createEventsFromSpreadsheet() {
// Open the spreadsheet and get the data.
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
const ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
const sheet = ss.getSheets()[0];
/** @type {string[][]} */
const data = sheet.getDataRange().getValues();

// Remove any frozen rows from the data, since they contain headers.
data.splice(sheet.getFrozenRows());

// Create an event for each row.
data.forEach(function(row) {
var title = row[0];
var description = row[1];
var emails = row[2];
const title = row[0];
const description = row[1];
const emailsStr = row[2];

// Split the emails into an array and remove extra whitespace.
emails = emails.split(',').map(function(email) {
const emails = emailsStr.split(',').map(function(email) {
return email.trim();
});

var now = new Date();
const now = new Date();
// Start the event at the next hour mark.
var start = new Date(now);
const start = new Date(now);
start.setHours(start.getHours() + 1);
start.setMinutes(0);
start.setSeconds(0);
start.setMilliseconds(0);
// End the event after 30 minutes.
var end = new Date(start);
const end = new Date(start);
end.setMinutes(end.getMinutes() + 30);

// Create the calendar event and invite the guests.
var event = CalendarApp.createEvent(title, start, end)
const event = CalendarApp.createEvent(title, start, end)
.setDescription(description);
emails.forEach(function(email) {
event.addGuest(email);
Expand Down
24 changes: 15 additions & 9 deletions mashups/sheets2chat.gs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @typedef {Object} SheetEditEvent
* @property {string} oldValue The old value of the cell.
* @property {string} value The new value of the cell.
*/

/**
* Posts a message to a Hangouts Chat room every time the spreadsheet is edited.
* This script must be attached to the spreadsheet (created in Google Sheets under
Expand All @@ -8,16 +14,16 @@
* "From spreadsheet", "On edit".
* - Click "Save".
*
* @param {Object} e The onEdit event object.
* @param {SheetEditEvent} e The onEdit event object.
*/
function sendChatMessageOnEdit(e) {
var range = SpreadsheetApp.getActiveRange();
var value = range.getValue();
var oldValue = e.oldValue;
var ss = range.getSheet().getParent();
const range = SpreadsheetApp.getActiveRange();
const value = range.getValue();
const oldValue = e.oldValue;
const ss = range.getSheet().getParent();

// Construct the message to send, based on the old and new value of the cell.
var changeMessage;
let changeMessage;
if (oldValue && value) {
changeMessage = Utilities.formatString('changed from "%s" to "%s"',
oldValue, value);
Expand All @@ -26,17 +32,17 @@ function sendChatMessageOnEdit(e) {
} else {
changeMessage = 'cleared';
}
var message = Utilities.formatString(
const message = Utilities.formatString(
'The range %s was %s. <%s|Open spreadsheet>.',
range.getA1Notation(), changeMessage, ss.getUrl());

// Follow these steps to create an incomming webhook URL for your chat room:
// https://developers.google.com/hangouts/chat/how-tos/webhooks#define_an_incoming_webhook
var webhookUrl = 'ENTER INCOMMING WEBHOOK URL HERE';
const webhookUrl = 'ENTER INCOMMING WEBHOOK URL HERE';

// Use the spreadsheet's ID as a thread key, so that all messages go into the
// same thread.
var url = webhookUrl + '&threadKey=' + ss.getId();
const url = webhookUrl + '&threadKey=' + ss.getId();

// Send the message.
UrlFetchApp.fetch(url, {
Expand Down
12 changes: 6 additions & 6 deletions mashups/sheets2contacts.gs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
*/
function createContactsFromSpreadsheet() {
// Open the spreadsheet and get the data.
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
const ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
const sheet = ss.getSheets()[0];
const data = sheet.getDataRange().getValues();

// Remove any frozen rows from the data, since they contain headers.
data.splice(sheet.getFrozenRows());

// Send a contact for each row.
data.forEach(function(row) {
var firstName = row[0];
var lastName = row[1];
var email = row[2];
const firstName = row[0];
const lastName = row[1];
const email = row[2];
ContactsApp.createContact(firstName, lastName, email);
});
}
17 changes: 9 additions & 8 deletions mashups/sheets2docs.gs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@
*/
function createDocsFromSpreadsheet() {
// Open the spreadsheet and get the data.
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
const ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
const sheet = ss.getSheets()[0];
/** @type {string[][]} */
const data = sheet.getDataRange().getValues();

// Remove any frozen rows from the data, since they contain headers.
data.splice(sheet.getFrozenRows());

// Create a document for each row.
data.forEach(function(row) {
var title = row[0];
var content = row[1];
var emails = row[2];
const title = row[0];
const content = row[1];
const emailsStr = row[2];

// Split the emails into an array and remove extra whitespace.
emails = emails.split(',').map(function(email) {
const emails = emailsStr.split(',').map(function(email) {
return email.trim();
});

// Create the document, append the content, and share it out.
var doc = DocumentApp.create(title);
const doc = DocumentApp.create(title);
doc.getBody().appendParagraph(content);
doc.addEditors(emails);
});
Expand Down
21 changes: 11 additions & 10 deletions mashups/sheets2drive.gs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,31 @@
*/
function createDriveFilesFromSpreadsheet() {
// Open the spreadsheet and get the data.
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
const ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
const sheet = ss.getSheets()[0];
/** @type {string[][]} */
const data = sheet.getDataRange().getValues();

// Remove any frozen rows from the data, since they contain headers.
data.splice(sheet.getFrozenRows());

// Create a PDF in Google Drive for each row.
data.forEach(function(row) {
var fileName = row[0];
var htmlContent = row[1];
var emails = row[2];
const fileName = row[0];
const htmlContent = row[1];
const emailsStr = row[2];

// Split the emails into an array and remove extra whitespace.
emails = emails.split(',').map(function(email) {
const emails = emailsStr.split(',').map(function(email) {
return email.trim();
});

// Convert the HTML content to PDF.
var html = Utilities.newBlob(htmlContent, 'text/html');
var pdf = html.getAs('application/pdf');
const html = Utilities.newBlob(htmlContent, 'text/html');
const pdf = html.getAs('application/pdf');

// Create the Drive file and share it out.
var file = DriveApp.createFile(pdf).setName(fileName);
const file = DriveApp.createFile(pdf).setName(fileName);
file.addEditors(emails);
});
}
17 changes: 9 additions & 8 deletions mashups/sheets2forms.gs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@
*/
function createFormsFromSpreadsheet() {
// Open the spreadsheet and get the data.
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
const ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
const sheet = ss.getSheets()[0];
/** @type {string[][]} */
const data = sheet.getDataRange().getValues();

// Remove any frozen rows from the data, since they contain headers.
data.splice(sheet.getFrozenRows());

// Create a form for each row.
data.forEach(function(row) {
var title = row[0];
var question = row[1];
var emails = row[2];
const title = row[0];
const question = row[1];
const emailsStr = row[2];

// Split the emails into an array and remove extra whitespace.
emails = emails.split(',').map(function(email) {
const emails = emailsStr.split(',').map(function(email) {
return email.trim();
});

// Create the form, append the question, and share it out.
var form = FormApp.create(title);
const form = FormApp.create(title);
form.addTextItem().setTitle(question);
form.addEditors(emails);
});
Expand Down
15 changes: 8 additions & 7 deletions mashups/sheets2gmail.gs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
*/
function sendEmailsFromSpreadsheet() {
// Open the spreadsheet and get the data.
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
const ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
const sheet = ss.getSheets()[0];
/** @type {string[][]} */
const data = sheet.getDataRange().getValues();

// Remove any frozen rows from the data, since they contain headers.
data.splice(sheet.getFrozenRows());

// Send an email for each row.
data.forEach(function(row) {
var subject = row[0];
var htmlMessage = row[1];
var emails = row[2];
const subject = row[0];
const htmlMessage = row[1];
const emails = row[2];

// Send the email.
GmailApp.sendEmail(emails, subject, null, {
GmailApp.sendEmail(emails, subject, '', {
htmlBody: htmlMessage
});
});
Expand Down
6 changes: 4 additions & 2 deletions mashups/sheets2maps.gs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
* @customFunction
*/
function COUNTY(address) {
var results = Maps.newGeocoder().geocode(address).results;
const results = Maps.newGeocoder().geocode(address).results;
if (!results || results.length === 0) {
throw new Error('Unknown address');
}
var counties = results[0].address_components.filter(function(component) {
/** @type {{long_name: string, types: string[]}[]} */
const addressComponents = results[0].address_components;
const counties = addressComponents.filter(function(component) {
return component.types.indexOf('administrative_area_level_2') >= 0;
});
if (!counties.length) {
Expand Down
21 changes: 11 additions & 10 deletions mashups/sheets2slides.gs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@
*/
function createPresentationsFromSpreadsheet() {
// Open the spreadsheet and get the data.
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
const ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
const sheet = ss.getSheets()[0];
/** @type {string[][]} */
const data = sheet.getDataRange().getValues();

// Remove any frozen rows from the data, since they contain headers.
data.splice(sheet.getFrozenRows());

// Create a presentation for each row.
data.forEach(function(row) {
var title = row[0];
var content = row[1];
var emails = row[2];
const title = row[0];
const content = row[1];
const emailsStr = row[2];

// Split the emails into an array and remove extra whitespace.
emails = emails.split(',').map(function(email) {
const emails = emailsStr.split(',').map(function(email) {
return email.trim();
});

// Create the presentation, insert a new slide at the start, append the content,
// and share it out.
var presentation = SlidesApp.create(title);
var slide = presentation.insertSlide(0, SlidesApp.PredefinedLayout.MAIN_POINT);
var textBox = slide.getShapes()[0];
const presentation = SlidesApp.create(title);
const slide = presentation.insertSlide(0, SlidesApp.PredefinedLayout.MAIN_POINT);
const textBox = slide.getShapes()[0];
textBox.getText().appendParagraph(content);
presentation.addEditors(emails);
});
Expand Down
6 changes: 3 additions & 3 deletions mashups/sheets2translate.gs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* under "Tools > Script editor").
*/
function onEdit() {
var range = SpreadsheetApp.getActiveRange();
var value = range.getValue();
const range = SpreadsheetApp.getActiveRange();
const value = range.getValue();
if (typeof value === 'string') {
var translated = LanguageApp.translate(value, null, 'en');
const translated = LanguageApp.translate(value, '', 'en');
range.setNote(translated);
}
}
Loading