Created
July 19, 2018 13:47
-
-
Save Mugurell/78300ba9056fe6b24d2db03099452a8a to your computer and use it in GitHub Desktop.
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 colorWorkdays() { | |
// get the sheet we want to work with. | |
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | |
// determine how long the sheet is | |
var lastColumn = sheet.getLastColumn() + 1; | |
// the sheet indexes are 1 based :-O | |
var workDaysHeaderRowIndex = 1; | |
var mondayColor = "#2fb726"; | |
var tuesdayColor = "#ccffcc"; | |
var wednesdayColor = "#b3ffb3"; | |
var thursdayColor = "#99ff99"; | |
var fridayColor = "#80ff80"; | |
// start from 3, account for the 2 columns for name and status | |
for (columnIndex = 3; columnIndex < lastColumn; ++columnIndex) { | |
var cell = sheet.getRange(workDaysHeaderRowIndex, columnIndex); | |
var value = cell.getValue(); | |
var color = "ffffff"; | |
if (value instanceof Date) { | |
var day = value.getDay(); // the day index in week [1-7] | |
switch(day % 5) { | |
case 0: | |
color = mondayColor; | |
break; | |
case 1: | |
color = tuesdayColor; | |
break; | |
case 2: | |
color = wednesdayColor; | |
break; | |
case 3: | |
color = thursdayColor; | |
break; | |
case 4: | |
color = fridayColor; | |
break; | |
} | |
cell.setBackground(color); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment