These utilities are grouped into related files, for simpler copy & paste to your scripts.
A couple of helper functions to convert to & from A1 notation.
function doGet(e) { | |
if(!e.parameters.sheetId) { | |
return HtmlService.createTemplateFromFile('Start').evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME); | |
} else { | |
var html = HtmlService.createTemplateFromFile('Viewer'); | |
//set variable of sheet id to post in hidden input field for async request when page loads | |
html.sheetName = SpreadsheetApp.openById(e.parameters.sheetId).getName(); | |
html.sheetId = e.parameters.sheetId; | |
// This is a simple, *insecure* hash that's short, fast, and has no dependencies. | |
// For algorithmic use, where security isn't needed, it's way simpler than sha1 (and all its deps) | |
// or similar, and with a short, clean (base 36 alphanumeric) result. | |
// Loosely based on the Java version; see | |
// https://stackoverflow.com/questions/6122571/simple-non-secure-hash-function-for-javascript | |
const simpleHash = str => { | |
let hash = 0; | |
for (let i = 0; i < str.length; i++) { | |
const char = str.charCodeAt(i); | |
hash = (hash << 5) - hash + char; |
function listFolders(folder) { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
sheet.appendRow(["Name", "Sharing Access", "Sharing Permission", "Get Editors", "Get Viewers", "Date", "Size", "URL", "Download", "Description", "Type"]); //writes the headers | |
var folder = DriveApp.getFolderById("YOUR_FOLDER_ID");//that long chunk of random numbers/letters in the URL when you navigate to the folder | |
var files = folder.getFiles();//initial loop on loose files w/in the folder | |
var cnt = 0; | |
var file; |
/** | |
* Creates a menu entry in the Google Docs UI when the document is opened. | |
* | |
* @param {object} e The event parameter for a simple onOpen trigger. To | |
* determine which authorization mode (ScriptApp.AuthMode) the trigger is | |
* running in, inspect e.authMode. | |
*/ | |
function onOpen(e) { | |
DocumentApp.getUi().createAddonMenu() | |
.addItem('Clean Table of Contents', 'cleanToC') |
This is a sample script for sorting the cells on Google Spreadsheet with the background colors using Google Apps Script.
Unfortunately, in the current stage, it seems that sort(sortSpecObj)
of Class Range cannot directly sort by the background colors of cells. But when Sheets API is used, this goal can be achieved. Here, "SortRangeRequest" of the method of "spreadsheets.batchUpdate" in Sheets API is used.
/* A bare-bones GithubClient, just used for commits */ | |
function GithubClient(owner, repo, username, passwordOrToken) { | |
this.owner = owner; | |
this.repo = repo; | |
this.username = username; | |
this.passwordOrToken = passwordOrToken; | |
} | |
/* |
function sync() { | |
var id="XXXXXXXXXX"; // CHANGE - id of the secondary calendar to pull events from | |
var today=new Date(); | |
var enddate=new Date(); | |
enddate.setDate(today.getDate()+7); // how many days in advance to monitor and block off time | |
var secondaryCal=CalendarApp.getCalendarById(id); | |
var secondaryEvents=secondaryCal.getEvents(today,enddate); |