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

标签 google-apps-script google-sheets text-formatting

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

enter image description here

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

最佳答案

根据 yesterday's release notes (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();

关于google-apps-script - 使用 Google App 脚本更改 Google Sheet 中部分单元格值的字体粗细,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43465402/

相关文章:

google-apps-script - Google Apps 脚本图表 vAxis.title 不工作

javascript - Google App Scripts 正则表达式 body.findText(searchPattern) 如果换行则返回 null

google-apps-script - copyTo 使用 {contentsOnly :true} not working

excel - 如何将Google Analytics(分析)数据导出到Google表格或Excel文件?

javascript - 如何处理 HTML 文件中的 scriptlet,而不是显示纯文本?

javascript - 为特定用户分别显示和隐藏谷歌表格

google-apps-script - 如何在Google Apps脚本中刷新工作表的单元格值

Java改变系统换行符

.net - 什么是 String.Format 的 WPF XAML 数据绑定(bind)等效项?

objective-c - 有一半的 UILabel 文本加粗,一半没有?