Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change whole row color in google script?

How can I change whole rows background color of active cell in google script?

SpreadsheetApp.getActiveRange().setBackgroundRGB(224, 102, 102)

The code above only changes active cells background color. But I need to change row of active cells background.

like image 627
effe Avatar asked Jun 28 '13 14:06

effe


1 Answers

Class Range and Class Sheet have methods you can use to pick the row that the cell is in. This is similar to the technique used in this answer.

SpreadsheetApp.getActiveSheet().getRange(SpreadsheetApp.getActiveRange().getRow(),1,1,SpreadsheetApp.getActiveSheet().getLastColumn()).setBackgroundRGB(224, 102, 102);

This does the same thing, broken down into easier-to-read lines:

var sheet = SpreadsheetApp.getActiveSheet();
var activeRange = SpreadsheetApp.getActiveRange();
var changeRange = sheet.getRange(activeRange.getRow(),1,1,sheet.getLastColumn());
changeRange.setBackgroundRGB(224, 102, 102);
like image 152
Mogsdad Avatar answered Sep 21 '22 12:09

Mogsdad