daily log 01.11.21

less than 1 minute read

Add conditional formatting for google sheets strikethrough

How to turn a cell with a strikethrough a certain color?

function lineThrough(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[1];//first sheet
var lr= sheet.getLastRow()
var lc=sheet.getLastColumn()
var range = sheet.getRange(2,1,lr,lc);//starting at the second row, first column
var results = range.getFontLines();

 for (var i=0;i<lr;i++) {
   for (var j=0;j<lc;j++ ) {
    if(results[i][j]== "line-through"){
    var color=sheet.getRange(i+2,j+1).setBackground("gray")//adjusting for the range offset of 2 and 1 above
   }}
 }}     

REFERENCES:

Google spreadsheet - Colour rows if Strikethrough - Stack Overflow

google sheets - Script to set cell color to none if the cell text has a strikethrough? - Stack Overflow

google sheets color isStrikethrough() - Google Search

google sheets - Script to Change Row Color when a cell changes text - Stack Overflow