Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

set range background color google script multiple colors

const myColorFunction = ({
  sheetName = "Form Responses 1",
  targetValue = "Open"
} = {}) => {

  const ss = SpreadsheetApp.getActiveSpreadsheet();

  const sheet = ss.getSheetByName(sheetName);

  const rng = sheet.getDataRange();

  const numHeaders = 1;

  const backgrounds = rng.getBackgrounds();
  const fontColors = rng.getFontColors();

  const newBckgs = backgrounds.map((row) => {
    const [firstCell] = row;

    if (firstCell === targetValue) {
      row[5] = "red";
    }

    return row;
  });

  const newColors = fontColors.map((row) => {
    const [firstCell] = row;

    if (firstCell === targetValue) {
      row[5] = "white";
    }

    return row;
  });

  rng.setBackgrounds(newBckgs);
  rng.setFontColors(newColors);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Webpack ReferenceError: process is not defined #871 electron vue 
Javascript :: strapi v4 populate 
Javascript :: vscode format - .prettierrc jsx singleQuote not work 
Javascript :: javascript Check Map Elements 
Javascript :: node js code for saving first middle and last name 
Javascript :: length array 
Javascript :: javascript create class 
Javascript :: ion change ionic angular 
Javascript :: javascript events 
Javascript :: react document viewer 
Javascript :: qr code terminal npm 
Javascript :: partial filter expression mongodb compass 
Javascript :: react component 
Javascript :: multiple ternary operator javascript 
Javascript :: javascript call and apply methods 
Javascript :: how to display image in html from json object 
Javascript :: rewrite expressjs url 
Javascript :: react filter array 
Javascript :: leaflet cdn 
Javascript :: js alert with multiple buttons 
Javascript :: javascript get last 2 item in array 
Javascript :: react hook form 
Javascript :: react-redux todo list 
Javascript :: how to update mongodb collection with a new field 
Javascript :: react insert variable into string 
Javascript :: find second largest number in array javascript 
Javascript :: class in javascript 
Javascript :: how to decode jwt token in angular 
Javascript :: how to delete a parameter with js 
Javascript :: javascript call stacks 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =