Created
January 6, 2019 00:14
-
-
Save codycodes/2b5c82038af8ea09301aece432920ee2 to your computer and use it in GitHub Desktop.
Google Apps Script Helper Functions for interacting with spreadsheet and Calendar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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