使用 Google App 脚本更改 Google Sheet 中部分单元格值的字体粗细

aks*_*aks 3 text-formatting google-sheets google-apps-script

要使用 Google App 脚本更改 Google trix 中单元格值的字体粗细,我使用了“setFontWeight”。但是,如果我需要以粗体显示给定的单词,而不是整个单元格值。请在下图中查看预期结果 -

在此处输入图片说明

如何使用 Google App 脚本更改 Google Sheet 中部分单元格值的字体粗细?

Rub*_*bén 8

根据昨天的发行说明(2019 年 1 月 22 日),电子表格服务已扩展为包括RichTextValue等新类,现在可以设置部分文本的格式。

来自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();
Run Code Online (Sandbox Code Playgroud)