0

How can I add an empty cell using Google Apps Script? Lets say I find a given value in a cell and I wan't to add an empty cell below or above it.

Also, how can I change the color of a substring inside a cell? Lets say my string is: TTP'112'223 , and I want the bold number in red: TTP'112'223

So far I haven't found any example on how to do this, thats why I don't have any initial code.

Thanks for your help.

EDIT:

For changing text style of a substring this example helped me:

// Sets all cells in range B2:D4 to have the text "Hello world", with 
"Hello" bolded.
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("B2:D4");
var bold = SpreadsheetApp.newTextStyle()
    .setBold(true)
    .build();
var richText = SpreadsheetApp.newRichTextValue()
    .setText("Hello world")
    .setTextStyle(0, 5, bold)
    .build();
 range.setRichTextValue(richText);

https://developers.google.com/apps-script/reference/spreadsheet/range#setrichtextvaluevalue

OrangeHat
  • 7
  • 6
  • 1
    Try [insertCells(shiftDimension)](https://developers.google.com/apps-script/reference/spreadsheet/range#insertCells(Dimension)) – Cooper Apr 07 '20 at 19:53
  • As for the font color take a look at this: https://stackoverflow.com/a/49289754/7215091 – Cooper Apr 07 '20 at 20:16
  • 1
    You could have found this yourself by Googling `changing font color of a substring in cell of a spreadsheet with google apps script` – Cooper Apr 07 '20 at 20:19
  • @Cooper doing that did not answer my questions. But a possible solution and added it above. – OrangeHat Apr 12 '20 at 19:50
  • @Cooper as for the insertCells function I get the following error: `TypeError: range.insertCells is not a function` – OrangeHat Apr 13 '20 at 04:51

0 Answers0