Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsernst/e833f3a9812fc943a10a to your computer and use it in GitHub Desktop.
Save dsernst/e833f3a9812fc943a10a to your computer and use it in GitHub Desktop.
// ?id=<GOOGLE_SHEET_ID>
function doGet(request) {
if (!request.parameter.id) {
return ContentService.createTextOutput(JSON.stringify(new Error('no Google Sheet id set')))
.setMimeType(ContentService.MimeType.JSON);
}
var cache = cacheNotesAndFormulas(request.parameter.id);
// Return cache as JSON
return ContentService.createTextOutput(JSON.stringify(cache))
.setMimeType(ContentService.MimeType.JSON);
}
function cacheNotesAndFormulas(spreadsheetId) {
return SpreadsheetApp
.openById(spreadsheetId)
.getSheets()
.reduce(function(cache, sheet) {
var sheetData = cache[sheet.getName()] = {};
var range = sheet.getDataRange();
sheetData.range = range.getA1Notation();
sheetData.notes = range.getNotes();
sheetData.formulas = range.getFormulas();
return cache;
}, {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment