Currently I have a working version of this by using conditional formatting in google sheets. Unfortunately the performance diminishes the more conditions I'm adding. I'd like to convert my conditional formatting to google script that runs every hour. This is basically a gantt chart that works perfectly for my needs.
The formula for conditional formatting is
=and(AF$2>=$L3,AF$2<=$M3)
where Column L is Start Date and Column M is End Date
Cell AF$2, AG$2, AH2... are Dates, starting from today, tomorrow, day after tomorrow, etc.
What would be the alternative to use google script instead. This is what I have so far:
function columnToLetter(column)
{
var temp, letter = '';
while (column > 0)
{
temp = (column - 1) % 26;
letter = String.fromCharCode(temp + 65) + letter;
column = (column - temp - 1) / 26;
}
return letter;
}
function setCellBackgrounds() {
// The name of the sheet to process.
var sheetName = "MySheet";
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var range = sheet.getRange("AF3:BJ100");
var values = range.getValues();
var colors = [];
for (var x = 0; x < values.length; x++) {
colors[x] = [];
for (var y = 0; y < values[x].length; y++) {
//trying to apply the formula "=and(AF$2>=$L3,AF$2<=$M3)" here but I'm getting an error
if (columnToLetter(32+y)+2 >= columnToLetter(12)+x && columnToLetter(32+y)+2 <= columnToLetter(13)+x ) {
colors[x][y] = '#999999';
} else {
//colors[x][y] = '#ffffff';
}
}
}
range.setBackgrounds(colors);
}
AF3:BJ100
is actually empty. – TheMaster