使用Google应用脚本在Google表格中更改部分单元格值的字体粗细。

5
使用Google应用脚本更改Google trix中单元格值的字体重量,我正在使用“setFontWeight”。但是,如果我需要使特定单词加粗,而不是整个单元格值。请参见下面图像中的预期结果 -

enter image description here

如何使用Google App脚本更改Google Sheet中部分单元格值的字体加粗?
2个回答

11
根据昨天的发布说明(2019年1月22日),电子表格服务已扩展到包括新类,如RichTextValue,现在可以设置部分文本的格式。
来自Class RichTextValueBuilder的示例。
// Creates a Rich Text value for the text "HelloWorld", with "Hello" bolded, and "World"
// italicized.
var bold = SpreadsheetApp.newTextStyle().setBold(true).build();
var italic = SpreadsheetApp.newTextStyle().setItalic(true).build();
var value = SpreadsheetApp.newRichTextValue()
    .setText("HelloWorld")
    .setTextStyle(0, 5, bold)
    .setTextStyle(5, 10, italic)
    .build();

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接