Guest User

Untitled

a guest
Jul 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. function colorWorkdays() {
  2. // get the sheet we want to work with.
  3. var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  4. // determine how long the sheet is
  5. var lastColumn = sheet.getLastColumn() + 1;
  6. // the sheet indexes are 1 based :-O
  7. var workDaysHeaderRowIndex = 1;
  8.  
  9. var mondayColor = "#2fb726";
  10. var tuesdayColor = "#ccffcc";
  11. var wednesdayColor = "#b3ffb3";
  12. var thursdayColor = "#99ff99";
  13. var fridayColor = "#80ff80";
  14.  
  15. // start from 3, account for the 2 columns for name and status
  16. for (columnIndex = 3; columnIndex < lastColumn; ++columnIndex) {
  17. var cell = sheet.getRange(workDaysHeaderRowIndex, columnIndex);
  18. var value = cell.getValue();
  19. var color = "ffffff";
  20.  
  21. if (value instanceof Date) {
  22. var day = value.getDay(); // the day index in week [1-7]
  23.  
  24. switch(day % 5) {
  25. case 0:
  26. color = mondayColor;
  27. break;
  28. case 1:
  29. color = tuesdayColor;
  30. break;
  31. case 2:
  32. color = wednesdayColor;
  33. break;
  34. case 3:
  35. color = thursdayColor;
  36. break;
  37. case 4:
  38. color = fridayColor;
  39. break;
  40. }
  41. cell.setBackground(color);
  42. }
  43. }
  44. }
Add Comment
Please, Sign In to add comment