In a Google Apps Script (GAS) for Sheets, I have multiple entries in a cell. I would like to change the font to RED (defined elsewhere in the code as const red = "#db4437";
) for the invalid entries. I have already captured the starting and ending character positions for the text ("txt") in question into "driveArray". "nfi" is the the last used index into driveArray. Since I could not figure out how to do it dynamically I hardcoded the first two cases with multiple 'setTextStyle' commands. I want to account for more invalid entries, do I have to hard code cases 3 & 4?
switch (nfi) {
case 0:
sht.getCurrentCell()
.setRichTextValue(SpreadsheetApp.newRichTextValue()
.setText(txt)
.setTextStyle(driveArray[0][0],driveArray[0][1], SpreadsheetApp.newTextStyle()
.setForegroundColor(red)
.build()
)
.build()
);
break;
case 1:
sht.getCurrentCell()
.setRichTextValue(SpreadsheetApp.newRichTextValue()
.setText(txt)
.setTextStyle(driveArray[0][0],driveArray[0][1], SpreadsheetApp.newTextStyle()
.setForegroundColor(red)
.build()
)
.setTextStyle(driveArray[1][0],driveArray[1][1], SpreadsheetApp.newTextStyle()
.setForegroundColor(red)
.build()
)
.build()
);
break;
}