How to change whole row color in google script?

2020-06-21 06:13发布

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.

1条回答
成全新的幸福
2楼-- · 2020-06-21 06:50

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);
查看更多
登录 后发表回答