Created
November 17, 2021 06:40
-
-
Save Metacowboy/3fd03156deb2480f75da13d983277878 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Create Google Calendar from Dispo Spreadsheet | |
* by Amir Esmann [email protected] | |
* | |
* Legent : Cell Red #ff0000. GEBLOCKT | |
* Cell GREEN #92d050. GEBUCHT | |
* Cell.YELLOW | |
* Todo: Check if Termin Exist | GET Aktive SHEET NAME | |
* DEF :https://stackoverflow.com/questions/50815817/google-script-select-an-entire-row-in-a-google-spreadsheet | |
*/ | |
function createCalendarEvent() { | |
let communityCalendar = CalendarApp.getCalendarById("[email protected]") | |
let sheet = SpreadsheetApp.getActiveSheet(); | |
var range = sheet.getRange('B47:S47'); | |
sheet.setActiveRange(range); | |
Logger.log("currentCell"); | |
var selection = sheet.getSelection(); | |
// Current cell: A1 | |
var currentCell = selection.getCurrentCell(); | |
// Active Range: B47:AK47 | |
var activeRange = selection.getActiveRange(); | |
Logger.log(currentCell); | |
/** | |
let schedule = sheet.getDataRange().getValues(); | |
schedule.splice(0, 2); | |
schedule.forEach(function(entry){ | |
communityCalendar.createEvent(entry[2], entry[0] ,entry[1]); | |
}); | |
*/ | |
} | |
//@OnlyCurrentDoc | |
function iterateThroughRows() { | |
//var monat = "OKTOBER" Def | |
var bookinttl = 'SERVUS BLAU'; | |
let communityCalendar = CalendarApp.getCalendarById("[email protected]") | |
var date = new Date(); | |
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1); | |
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0); | |
var thisDay = new Date(firstDay); | |
// GEt Atkive Sheet NAme | |
let mymonth = SpreadsheetApp.getActiveSheet().getName(); | |
let monat = mymonth.split(' ')[0]; | |
Logger.log(monat) | |
var sheet = SpreadsheetApp.getActive().getSheetByName(mymonth); | |
var data = sheet.getDataRange().getValues(); | |
// Loop all rows to find user | |
data.forEach(function (row) { | |
row.splice(0, 2); | |
row.splice(1, 2); | |
//Logger.log(row[0]); | |
var i = 1; | |
if (row[0] == "Amir Esmann"){ | |
row.pop(); | |
row.pop(); | |
Logger.log(row); | |
// Loop Days Daterange | |
while(thisDay <= lastDay && i++){ | |
//Logger.log(thisDay); | |
//Logger.log(row[i]); | |
// GEt Color red Blocked Dates by ROW | |
let alphabet = (i + 9).toString(36).toUpperCase(); | |
Logger.log("Alphabet row:" + alphabet); | |
var cell = sheet.getRange(alphabet+"47"); | |
var cellcolor = cell.getBackground(); | |
// EIN AKTIVER TERMIN GEBUCHT ODER GEBLOCKT | |
if(cellcolor !== '#ffffff'){ | |
Logger.log(cell.getBackground()); | |
} | |
// CHECK IF TERMIN EXIST (Prevent dubble) contain the term "SERVUS" | |
var eventday = communityCalendar.getEventsForDay(thisDay, {search: bookinttl}); | |
//Logger.log('Num Servus Booking Today: ' + eventday.length); | |
// Literate My Termine Row No Dub | |
if((row[i] == 1) && (eventday.length < 1)){ | |
Logger.log("GEBUCHT") | |
var event = communityCalendar.createAllDayEvent( | |
bookinttl, | |
thisDay, | |
{location: 'The Moon'}); | |
event.setColor('11'); | |
} | |
var newDate = thisDay.setDate(thisDay.getDate() + 1); | |
thisDay = new Date(newDate); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment