Skip to content

Instantly share code, notes, and snippets.

View mogsdad's full-sized avatar

David Bingham mogsdad

View GitHub Profile
@mogsdad
mogsdad / GCalUtils.md
Last active May 10, 2021 17:39
Collection of Google Calendar related utility functions for Google Apps Script.

Google Calendar Utilities

getEventsWithGuest

Gets all events that occur within a given time range, and that include the specified guest email in the guest list.

###Parameters:###

Calendar Copier

This Google Apps Script runs in a spreadsheet, where it prompts the user for the identity of two calendars, and a range of dates, then copies the corresponding events from one calendar to the other.

Caveats

This script is incomplete, ignoring a number of event attributes. (Feel free to enhance it, if you wish!) There are also some known issues:

  • All Day Events aren't really all day events. The createAllDayEvent() method should take care of this, but doesn't. Google Bug.
  • Recurrence isn't supported. (You can't find out the recurrence of existing events, so cannot recreate it.)

SheetConverter library (formerly "Spreadsheet to HTML")

This is the source repository for the SheetConverter Google Apps Script library.

Libary documentation is available here.

Caveats

This script is incomplete, ignoring some types of formatting. (Feel free to fork and enhance it, if you wish! Broadly applicable enhancements can be merged and the library updated) There are also some known issues:

@mogsdad
mogsdad / Google Apps Script Survey Workflow.md
Last active August 1, 2022 07:48
Google Apps Script workflow for an email survey. Written in response to StackOverflow question 18668828. http://stackoverflow.com/a/18669532/1677912

Google Apps Script Survey Workflow

The components involved in this workflow are:

  • A script to generate and send an email with an HTML form.
  • An html template for that email, which allows us to customize the email for each recipient.
  • A doPost() function to handle responses. The script must be [deployed as a Web App][1].
  • A spreadsheet to collect responses. The script will be contained in the spreadsheet, and extends the spreadsheet UI with a menu for sending a copy of the survey. (It could be adapted for standalone use, without the UI component.)

Here is an example of such a workflow, conducting a Commuting Survey. Recipients will receive a survey email like this:

Google Apps Script Gmail Utilities

##sendAndLabel(recipient, subject, body, options, label)##

An alternative to GmailApp.sendEmail(), which applies a label to the message thread in the sender's account.

Sends an email message with optional arguments. The email can contain plain text or an HTML body. The size of the email

Google Apps Script Document Utilities

  • getAllLinks.js

  • getAllLinks(element) - returns array of all UrlLinks in Document

  • findAndReplaceLinks(searchPattern,replacement) - changes all matching links in Document

  • changeCase.js - Document add-in, provides case-change operations in the add-in Menu.

  • onOpen - installs "Change Case" menu

  • _changeCase - worker function to locate selected text and change text case. Case conversion is managed via callback to a function that accepts a string as a parameter and returns the converted string.

  • helper functions for five cases

@mogsdad
mogsdad / uniqueFrom.js
Created January 9, 2014 18:48
Javascript Array extension to find the members of a set (array) that are unique, that is they are not members of other sets. See http://goo.gl/ArHbvb.
/**
* Returns a non-destructive Array of elements that are not found in
* any of the parameter arrays.
*
* @param {...Array} var_args Arrays to compare.
*/
Array.prototype.uniqueFrom = function() {
if (!arguments.length)
return [];
var a1 = this.slice(0); // Start with a copy
@mogsdad
mogsdad / dataTableFromArray.js
Created January 30, 2014 17:51
Google Apps Script's Charts Service uses a DataTable object as the source data for visualizations and tables. There is a built-in method that can create a DataTable given a Spreadsheet Range, but if you have a javascript table or array that you want to visualize, you need to use the DataTableBuilder class' primitive methods. This function simpli…
/**
* Produce a dataTable object suitable for use with Charts, from
* an array of rows (such as you'd get from Range.getValues()).
* Assumes labels are in row 0, and the data types in row 1 are
* representative for the table.
*
* @param {Array} data Array of table rows
*
@ @returns {DataTable} Refer to GAS documentation
*/

Apps Script Google+ Domains Service Utilities

  • PlusDomainUtils.js
  • getProfile(userId) - Retreive Google+ Profile for the given userId.
  • getPicUrl(userId) - Return simple url to Google+ profile picture for the given user.
  • test_getPicUrl() - test harness
  • getPathFromUrl(url) - strip query string to return bare URL

Google Apps Script Spreadsheet Utilities and Custom Functions#

These utilities are grouped into related files, for simpler copy & paste to your scripts.

ConvertA1.gs

A couple of helper functions to convert to & from A1 notation.

cellA1ToIndex( string cellA1, number index )