Reputation: 869
I have a Google sheet with default textstyle cell A1
. I want to set a new text value to the cell with different textstyles:
function setTextToCell (){
let comment = Browser.inputBox('Your comment');
let commentTextStyle = SpreadsheetApp.newTextStyle().setForegroundColor('red');
comment = SpreadsheetApp.newRichTextValue().setText(comment).setTextStyle(commentTextStyle).build();
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(`My comment - ${comment}`)
}
I expect to see default font color for My comment -
and red for text from input box.
It's does not work. Where I'm wrong and how to fix it?
Upvotes: 0
Views: 300
Reputation: 50482
.setValue
only sets the value. To set rich text, use .setRichTextValue
. Text style should also be offseted as necessary.
richComment = SpreadsheetApp
.newRichTextValue()
.setText(`My comment - ${comment}`)// modified
.setTextStyle(13, 13+comment.length-1, commentTextStyle)//modified
.build();
SpreadsheetApp
.getActiveSheet()
.getRange('A1')
.setRichTextValue(richComment)//modified
Upvotes: 2