Javascript 如何为Google工作表单元格中的特定单词设置textstyle?
我有一个带有默认文本样式单元格的谷歌工作表Javascript 如何为Google工作表单元格中的特定单词设置textstyle?,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,我有一个带有默认文本样式单元格的谷歌工作表A1。我想为具有不同文本样式的单元格设置新的文本值: 函数setTextToCell(){ let comment=Browser.inputBox(“您的注释”); 让commentTextStyle=SpreadsheetApp.newTextStyle().setForegroundColor('red'); comment=SpreadsheetApp.newRichTextValue().setText(comment).setTextSty
A1
。我想为具有不同文本样式的单元格设置新的文本值:
函数setTextToCell(){
let comment=Browser.inputBox(“您的注释”);
让commentTextStyle=SpreadsheetApp.newTextStyle().setForegroundColor('red');
comment=SpreadsheetApp.newRichTextValue().setText(comment).setTextStyle(commentTextStyle.build();
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(`My comment-${comment}`)
}
.setValue
仅设置值。要设置富文本,请使用。还应根据需要进行抵消
片段:
.setValue
仅设置值。要设置富文本,请使用。还应根据需要进行抵消
片段:
richComment = SpreadsheetApp
.newRichTextValue()
.setText(`My comment - ${comment}`)// modified
.setTextStyle(13, 13+comment.length-1, commentTextStyle)//modified
.build();
SpreadsheetApp
.getActiveSheet()
.getRange('A1')
.setRichTextValue(richComment)//modified