• Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

75
Views
How can i set the background cell values color using **.push** array in app script?

I have been trying to change the background color of the cell value based on the STATUS. If the status is OLD FILE then i would like to set the background color of the cell red, and if the status is NEW FILE, i would like to set it into green (as shown in the sample).

enter image description here

Here is the code:

const cells = sheet.getRange("I2:I" + sheet.getLastRow())
const cellValues = cells.getValues()
Logger.log(cellValues)

const newValues = []
var backGrounds = []

cellValues.forEach((row) => {
  if (row[0] === "new file") {
     newValues.push(['OLD FILE'])
   }
   else if (row[0] === "OLD FILE" || row[0] === "NEW FILE") {
     newValues.push([row[0]])
   }
   else {
     newValues.push(['NEW FILE'])
     backGrounds.push(['00ff00'])
   }
   })

   cells.setValues(newValues).setBackground(backGrounds)
   }

I have tried using the backGrounds.push(['00ff00']) and .setBackground(backGrounds) but it still not changing.

How can i change the the cell background color based on the status?

9 months ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.