Home > Mobile >  Google Sheets Color diferent cel strings
Google Sheets Color diferent cel strings

Time:04-30

I want to color my cels with 3 colors of text, is possible via conditional formating of JS? TY !

Example.

8♠ 6♦ 5♣

3 colors in one cell

CodePudding user response:

Indeed you have to use the enter image description here

CodePudding user response:

const spreadsheet = SpreadsheetApp.getActiveSpreadsheet()
const sheet = spreadsheet.getSheetByName('Sheet1')

function changeColor() {
  const range = sheet.getRange("A1:A5");
  const values = range.getValues()

  black = SpreadsheetApp.newTextStyle()
    .setForegroundColor("black")
    .build();

  blue = SpreadsheetApp.newTextStyle()
    .setForegroundColor("blue")
    .build();

  green = SpreadsheetApp.newTextStyle()
    .setForegroundColor("green")
    .build();

  for (value of values){
    richText = SpreadsheetApp.newRichTextValue()
    .setText(value)
    .setTextStyle(0, 2, black)
    .setTextStyle(3, 5, blue)
    .setTextStyle(6, 8, green)
    .build();
    
    range.setRichTextValue(richText);
  }
}
  • Related