使用Google App脚本更改Google表格中部分单元格值的字体粗细 [英] Changing font-weight of partial cell value in Google Sheet using Google App script

查看:125
本文介绍了使用Google App脚本更改Google表格中部分单元格值的字体粗细的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

To change the font weight of cell value in a Google trix using Google App script, I am using 'setFontWeight'. However, if I need to make a given word in bold, and not the entire cell value. Please see the expected result in image below -

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

How can I change font-weight of partial cell value in Google Sheet using Google App script ?

推荐答案

根据昨天的发行说明(2019年1月22日),扩展了电子表格服务,以包括新的类,例如

According the the yesterday's release notes (January 22, 2019), the Spreadsheet Service was extended to include new classes like RichTextValue which makes now possible to set formatting for partial text.

来自 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表格中部分单元格值的字体粗细的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆