Skip to content

Instantly share code, notes, and snippets.

@codycodes
Created Jan 6, 2019
Embed
What would you like to do?
Google Apps Script Helper Functions for interacting with spreadsheet and Calendar
function getEvents(calId){
/*
Gets the events which occur in the next 24 hours for the given calendar ID
*/
cal = CalendarApp.getCalendarById(calId);
var now = new Date();
var twentyFourHoursFromNow = new Date(now.getTime() + (24 * 60 * 60 * 1000));
var events = cal.getEvents(now, twentyFourHoursFromNow);
return events;
}
function getSheet(sheetNum){
/* Gets the sheet specified in sheetNum */
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheets()[sheetNum];
return ss;
}
function checkSheetName(ss, sheetName) {
/* Useful in case sheets indexes change to verify that you're acting on the sheet given in "sheetName" */
var currentSheetName = ss.getSheetName();
var isCorrectSheet = false;
if (currentSheetName == sheetName){
isCorrectSheet = true;
}
return isCorrectSheet;
};
function getLastFilledRow(ss, col){
/*
Get the last row from the spreadsheet
*/
var column = ss.getRange(col + ":" + col);
var values = column.getValues();
// check if column is empty
var ct = 0;
while ( values[ct][0] != "" ){
ct++;
}
return (ct);
}
function createHeader(ss, header) {
var range = ss.getRange(1,1,1,header[0].length);
range.setValues(header);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment