Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Mugurell/78300ba9056fe6b24d2db03099452a8a to your computer and use it in GitHub Desktop.
Save Mugurell/78300ba9056fe6b24d2db03099452a8a to your computer and use it in GitHub Desktop.
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