Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何为Google工作表单元格中的特定单词设置textstyle?_Javascript_Google Apps Script_Google Sheets - Fatal编程技术网

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