Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
- }
Add Comment
Please, Sign In to add comment