apps-script-samples
apps-script-samples copied to clipboard
could not set the background color the filtered rows.
tried other methods as well, but didn't worked out. the display function over the filtered screen also seems to be not working.
function applyFilterConditionsAndColor(sheet) { var filterRange = sheet.getDataRange(); var existingFilter = filterRange.getFilter(); if (existingFilter !== null) { existingFilter.remove(); }
// Apply filter condition to column N where the value is "ToCall_Sheet" var criteria = SpreadsheetApp.newFilterCriteria() .whenTextEqualTo("ToCall_Sheet") .build();
filterRange.createFilter().setColumnFilterCriteria(14, criteria); // Assuming "ToCall_Sheet" is in column N (index 14)
// Get the filtered rows (excluding header) var filteredRows = filterRange.getValues().slice(1);
// Set background color to yellow for the filtered rows for (var i = 0; i < filteredRows.length; i++) { sheet.getRange(i + 2, 1, 1, sheet.getLastColumn()).setBackground('yellow'); } }
but the most fraustating thing is that this below code works out of nowhere: the sheet is the main subsheet where the operation is carried out. and the filter view is not accessed by it. but it is literally coloring the filtered rows. someone tell me it is not the fault of the compiler optimization error thing. function applyColor(sheet){ var DELETE_VAL = "SEND TO WHATSAPP"; var COL_TO_SEARCH = 14;
// Get the range values var rangeValues = sheet.getDataRange().getValues(); var range = sheet.getDataRange(); // Filter out rows where column N is "DELETE" var filteredValues = rangeValues.filter(function(row) { return row[COL_TO_SEARCH - 1] !== DELETE_VAL; });
// Clear the content of the entire sheet range.setBackground("red");
}
anyone ?? where is the response to the issue?
i have found the solution.