Skip to content

Instantly share code, notes, and snippets.

@hinklefoxmail hinklefoxmail/Planner.gs Secret
Created Sep 3, 2017

Embed
What would you like to do?
Lesson Planner
ffunction findClasses() {
var user = Session.getActiveUser().getEmail();
var sheet = SpreadsheetApp.getActiveSheet();
var sheetName = sheet.getName();
var calendar = CalendarApp.getCalendarById(user);
var now = new Date();
var endTime = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('config').getRange(1, 2).getValue();
var events = calendar.getEvents(now, endTime);
for (var i = 0; i < events.length; i++){
var event = events[i];
var title =events[i].getTitle()
if (sheetName == title){
Logger.log(title);
var time = Utilities.formatDate(event.getStartTime(), "GMT+1", "MM/dd");
var time = "'"+time
sheet.appendRow([time]);
}
}
}
function doPaperwork(){
var sheet = SpreadsheetApp.getActiveSheet();
var user = Session.getActiveUser().getEmail();
var userName = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('config').getRange(2, 2).getValue();
var folderName = 'Lesson Plans for '+userName
try{
var folder = DriveApp.getFoldersByName(folderName).next();
}
catch(e){
var folder = DriveApp.createFolder(folderName);
folder.addEditor(user);
}
var sheetName = sheet.getName();
var standarSheet = SpreadsheetApp.getActive().getSheetByName(sheetName+' Standards');
var data = sheet.getActiveRange().getValues();
var header = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
for (var i = 0; i < data.length; i++){
var row = data[i];
var templateName = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('config').getRange(3, 2).getValue();
try{
var template = DriveApp.getFilesByName(templateName).next();
}
catch(e){
var template = DriveApp.getFileById('1ih_E4MtBtjOSaNy2PKl10_bIztVXbW2Sdd_bJzo_M1E').makeCopy(templateName);
}
var docId = template.makeCopy(sheetName+' Lesson Plan '+row[0], folder).getId();
var doc = DocumentApp.openById(docId);
var body = doc.getBody();
for (var j = 0; j < row.length; j++){
if (j !== 1){
body.replaceText(header[j], row[j])
}
try{
var standardNo = standarSheet.getRange(row[1], 1).getValue();
var standardInfo = standarSheet.getRange(row[1], 2).getValue();
}
catch(e){
var standardInfo = row[1];
var standardNo = '';
}
body.replaceText('{standardNo}', standardNo);
body.replaceText('{standardText}', standardInfo);
body.replaceText('{sheetName}', sheetName);
body.replaceText('{name}', userName);
}
}
}
function onOpen(){
SpreadsheetApp.getUi().createMenu('Do Paperwork').addItem('Do Plans', 'doPaperwork').addItem('Find Classes', 'findClasses').addToUi();
}
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.