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 / 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 / createPDF.gs
Last active December 29, 2023 07:49
Google Apps Script that merges the values from a Google Spreadsheet into a Google Doc template (does a mail merge) to create a GDoc or PDF. More details can be found at www.andrewroberts.net/2014/10/google-apps-script-create-pdf/. Go to https://tinyurl.com/yd8v2do2 if you would like me to set it up for you.
//
// Create a PDF by merging values from a Google spreadsheet into a Google Doc
// ==========================================================================
//
// Demo GSheet & script - http://bit.ly/createPDF
// Demo GDoc template - 1QnWfeGrZ-86zY_Z7gPwbLoEx-m9YreFb7fc9XPWkwDw
//
// Config
// ======
@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 / 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 / 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 / exportSpreadsheet.gs
Last active August 10, 2023 09:53 — forked from Spencer-Easton/exportSpreadsheet.gs
Example on how to export a Google sheet to various formats, includes most PDF options. Updated from comments in [Spencer Easton's Gist](https://gist.github.com/Spencer-Easton/78f9867a691e549c9c70)
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
@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 / 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
// ==============
//
@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 / 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]
*/