Recently, console logging became available for Google Apps Script projects. It used to
be impossible to use the Log service that comes with the GAS runtime, but now all
you need to do is throw
an exception. Exceptions get logged in stackdriver logging and
when enabled, unhandled exceptions will not stop your script execution. This adds up
to nearly 0 lag if you are using this feature (?) by purposely throwing exceptions, and you
can get creative with your error message to avoid having to expand stackdriver's log messages
(which are pretty comprehensive stacktraces!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string} value - value to test | |
* @param {array} valuesToTest | |
* | |
* @return the best match in the test array | |
*/ | |
function getBestMatch(value, valuesToTest) { | |
var results = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function exportSpreadsheet() { | |
//All requests must include id in the path and a format parameter | |
//https://docs.google.com/spreadsheets/d/{SpreadsheetId}/export | |
//FORMATS WITH NO ADDITIONAL OPTIONS | |
//format=xlsx //excel | |
//format=ods //Open Document Spreadsheet | |
//format=zip //html zipped | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function testNumber() { | |
var value = 1234.56789 | |
var a = format(value, {numberOfDecimalPlaces: 2}) | |
debugger | |
} | |
function testDate() { | |
var value = new Date() | |
var a = format(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateRandomString(n) { | |
var chars = ['a', 'b','c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; | |
chars.push('A', 'B', 'C', 'D', 'E', 'F','G','H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); | |
var randomString = ''; | |
for (i=0; i < n; i++) { | |
r = Math.random(); | |
r = r * 61; | |
r = Math.round(r); | |
randomString = randomString + chars[r]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 34567890123456789012345678901234567890123456789012345678901234567890123456789 | |
// JSHint - TODO | |
/* jshint asi: true */ | |
(function() {"use strict"})() | |
// Properties_.gs | |
// ============== | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dev: andrewroberts.net | |
// Replace this with ID of your template document. | |
var TEMPLATE_ID = '' | |
// var TEMPLATE_ID = '1wtGEp27HNEVwImeh2as7bRNw-tO4HkwPGcAsTrSNTPc' // Demo template | |
// Demo script - http://bit.ly/createPDF | |
// You can specify a name for the new PDF file here, or leave empty to use the | |
// name of the template. Placeholders can also be placed in here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 34567890123456789012345678901234567890123456789012345678901234567890123456789 | |
// JSHint - TODO | |
/* jshint asi: true */ | |
(function() {"use strict"})() | |
// API_.gs | |
// ======= | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* For each placeholder - "{{[placeholder]}}", strip out any HTML and replace | |
* it with the appropriate key value. An example use of this could be using the | |
* HTML from a draft GMail as a template. | |
* | |
* E.g. If the obect were: | |
* | |
* {PlaceHolder1: newValue} | |
* | |
* In the template "{{PlaceHolder1}}" would be replaced with "newValue" even |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
PDF Creator - Send multiple PDFs | |
================================ | |
On selecting a number of contiguous rows and clicking "Create PDFs > Create PDFs | |
for selected rows" this script constructs a PDF for each selected row in the | |
attached GSheet. | |
The value in the "File Name" column is used to name the file and - if there is a |
NewerOlder