使用 Google App 脚本更改 Google Sheet 中部分单元格值的字体粗细
Changing font-weight of partial cell value in Google Sheet using Google App script
要使用 Google App 脚本更改 Google trix 中单元格值的字体粗细,我正在使用 'setFontWeight'。但是,如果我需要用粗体显示给定的单词,而不是整个单元格的值。请在下图中查看预期结果 -
如何使用 Google App 脚本更改 Google Sheet 中部分单元格值的字体粗细?
遗憾的是(截至目前)您无法通过 Apps 脚本以编程方式修改部分单元格。这是一个已经发生的问题。
根据 yesterday's release notes (January 22, 2019), the Spreadsheet Service was extended to include new classes like 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 App 脚本更改 Google trix 中单元格值的字体粗细,我正在使用 'setFontWeight'。但是,如果我需要用粗体显示给定的单词,而不是整个单元格的值。请在下图中查看预期结果 -
如何使用 Google App 脚本更改 Google Sheet 中部分单元格值的字体粗细?
遗憾的是(截至目前)您无法通过 Apps 脚本以编程方式修改部分单元格。这是一个已经发生的问题。
根据 yesterday's release notes (January 22, 2019), the Spreadsheet Service was extended to include new classes like 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();