V
V
Vladimir Zuev2020-07-23 08:34:35
Google Apps Script
Vladimir Zuev, 2020-07-23 08:34:35

How to recolor text in selected cells?

Hello.
There is a google spreadsheet. It contains several cells. How to recolor the text in these selected cells?
This is how we recolor when the cells are known.

var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRangeList(['A4', 'A8', 'A13', 'A19', 'A23']).activate()
  .setFontColor('#ff0000');

And if they are only selected. How then to recolor the text in these selected cells? Please help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Grigory Boev, 2020-07-23
@vladd56

Here is a code that will help:

function rePaint() {  
  SpreadsheetApp.getActive().getActiveRangeList().setBackground('#ff9900');
};

You can see in the
demo table

V
Vladimir Zuev, 2020-07-23
@vladd56

Wrote a function. But it doesn't color the text. Where is the mistake?

function ColorRange(){
  const sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Прейскурант товаров");
  //sheet1.getActiveRange().setFontColor('#00ff00');
  sheet1.getActive().getActiveRangeList().setFontColor('#00ff00');
};

This one worked
function ColorRange(){
  const sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Прейскурант товаров");
   sheet1.getActiveRangeList().setFontColor('#00ff00');
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question