How to change background color of a row

Posted by: tedin_uriburu on 30 October 2019, 2:25 pm EST

  • Posted 30 October 2019, 2:25 pm EST

    I want to change the background color and/or font color for every row depending on a value in the row itself, how can I do this? do I need to change color of every cell in every row?

    Thanks,

  • Posted 31 October 2019, 2:03 am EST

    Hi,

    If you need to change the background color of row only once then you could simply iterate over the rows and use getRange() to get the row and then backColor() method to update the back color as shown below:

    // update color of 3rd row
    // check condition
    let val = sheet.getValue(0, 2);
    if(val > 5){
      // update color
      let rowIndex = 2;
      sheet.getRange(rowIndex, -1, 1, -1).backColor("lightgreen");
    }
    

    However, if you need to be able to dynamically change the color based on the cell value(in cases when the cell is editable), then we would suggest you use the conditional formatting feature. Please refer to the following demo sample demonstrating the same:

    https://www.grapecity.com/demos/spread/JS/TutorialSample/Features/ConditionalFormat/basicConditionalFormat/purejs

    Regards

    Sharad

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels