Skip to content

Instantly share code, notes, and snippets.

View andrewroberts's full-sized avatar
💭
Cranking out the code... 👨‍💻

Andrew Roberts andrewroberts

💭
Cranking out the code... 👨‍💻
View GitHub Profile
@andrewroberts
andrewroberts / LogAppsScriptConfig
Created August 10, 2016 22:10
Log and clear the contents of Apps Script properties, triggers, etc
/**
* Clear all of the config
*/
function clearConfig() {
Logger.log('Delete Local Script Properties:')
if (PropertiesService.getScriptProperties() !== null) {
Logger.log(PropertiesService.getScriptProperties().deleteAllProperties())
Logger.log(' Deleted')
@andrewroberts
andrewroberts / EmailPDFOfFormSubmission.gs
Last active September 21, 2023 06:56
Email a PDF of a Google Form submission.
/*
PDF Create - Email on form submit
=================================
This script creates a PDF populated with the values submitted in a
Google form.
The "on form submit" trigger needs to be manually created:
@andrewroberts
andrewroberts / convertSpreadsheetToPdf.gs
Last active September 15, 2022 17:21
Convert a multi-sheet Google Spreadsheet into a PDF, with option to email it.
/*
* Save spreadsheet as a PDF
*
* Based on Dr.Queso's answer in http://stackoverflow.com/questions/30367547/convert-all-sheets-to-pdf-with-google-apps-script/30492812#30492812
*
* @param {String} email Where to send the PDF [OPTIONAL]
* @param {String} spreadsheetId Or the active spreadsheet[OPTIONAL]
* @param {String} sheetName The tab to output [OPTIONAL]
* @param {String} PdfName [OPTIONAL]
*/
@andrewroberts
andrewroberts / PDFCreator_EmailAllResponses
Last active August 31, 2023 06:38
Google Apps Script to create a PDF from each of the rows in a Google Sheet
/*
PDF Creator - Email all responses
=================================
When you click "Create PDF > Create a PDF for each row" this script
constructs a PDF for each row in the attached GSheet. The value in the
"File Name" column is used to name the file and - if there is a
value - it is emailed to the recipient in the "Email" column.
@andrewroberts
andrewroberts / StackTraces-Logging-GAS.md
Last active July 7, 2017 11:58 — forked from hlecuanda/StackTraces-Logging-GAS.md
Example using Stackdriver logging for debugging a custom function for sheets in Google Apps Script. / Writing a Caching custom function

Logging custom functions using stackdriver in google apps script

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!)

Setup

@andrewroberts
andrewroberts / PDFCreator_SendMultiplePDFs.gs
Last active November 15, 2020 19:43
Google Apps Script for creating and emailing multiple PDFs using data from a Google Sheet and a Google doc template.
/*
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
@andrewroberts
andrewroberts / fillInHtmlTemplate.gs
Created September 17, 2017 10:02
Google Apps Script function to replace placeholder values in an HTML template (from a draft GMail for example)
/**
* 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
@andrewroberts
andrewroberts / API_.gs
Created September 25, 2017 11:02
Google Apps Script snippet for accessing the Quick Books Online API
// 34567890123456789012345678901234567890123456789012345678901234567890123456789
// JSHint - TODO
/* jshint asi: true */
(function() {"use strict"})()
// API_.gs
// =======
//
@andrewroberts
andrewroberts / createPDF_filename.gs
Last active November 1, 2023 16:41
This is a Google Apps Script that creates a PDF file using a Google Doc template and the values in a Google Spreadsheet. It is based on www.andrewroberts.net/2014/10/google-apps-script-create-pdf/ but allows placeholders to be used in the filename.
// 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.
@andrewroberts
andrewroberts / Properties_.gs
Created July 16, 2018 09:42
Google Apps Script snippet to manage and store persistent state. Uses both Firebase (FirebaseApp library), CacheService and BBLog for logging.
// 34567890123456789012345678901234567890123456789012345678901234567890123456789
// JSHint - TODO
/* jshint asi: true */
(function() {"use strict"})()
// Properties_.gs
// ==============
//