Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 -

enter image description here

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

like image 767
aks Avatar asked Apr 18 '17 06:04

aks


People also ask

Can you have two fonts in a single cell in Google spreadsheet?

@player0 It is possible in a single cell even when doing it manually. You just need to select that part of the text and change font.

How do I increase font size in Google script?

setFontSize(fontSize) Sets the font size of the text, in points.

How do you bold in Google Sheets formula?

To make text bold: Select the text you want to modify. To bold text, click the Bold text button or press Ctrl+B (Windows) or Command+B (Mac) on your keyboard. The text will change to bold.


2 Answers

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();
like image 104
Rubén Avatar answered Oct 18 '22 18:10

Rubén


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

like image 36
Hari Das Avatar answered Oct 18 '22 19:10

Hari Das