Changing font-weight of partial cell value in Google Sheet using Google App script

别来无恙 提交于 2019-12-20 03:44:16

问题


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 -

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


回答1:


Unfortunately there is no way (as of now) you can modify part of a cell programically through Apps Script. Here is an issue already going on for this.

https://issuetracker.google.com/issues/36764247




回答2:


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.

Example from 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();


来源:https://stackoverflow.com/questions/43465402/changing-font-weight-of-partial-cell-value-in-google-sheet-using-google-app-scri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!