google sheets, 2 font type name in 1 cell with script

81 views Asked by At

Part of text with font; libre barcode 39 extended and another part of the text; Arial in a cell (google sheets).

=if(AA3="","",CONCATENATE("",W3,"",char(10),AC3,"،",AB3))

This is my formula.

I found a script. The script changes the font size. The first problem is, after running, my formula will be converted into text. Is there a way to not change the formula to the text? And the second question, how to change the type of the font other than the font size (line 14)?


function myFunction() {
  const sheetName = "RC/12";  // Please set the sheet name.
  
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName(sheetName);
  const range = sheet.getRange("W3:W" + sheet.getLastRow());
  const richTextValues = range.getRichTextValues().map(([a]) => {
    const text = a.getText();
    const pos = text.indexOf("|");
    if (pos > -1) {
      const temp = a.getTextStyle(0, pos - 1);
      const textStyle = SpreadsheetApp.newTextStyle()
        .setFontSize(8)
        .setFont.Name = ("calabri")
        .setForegroundColor("Red")
        .setItalic(false)
        .setBold(false)
        .build();
      return [
        SpreadsheetApp.newRichTextValue()
        .setText(text)
        .setTextStyle(0, pos - 1, temp)
        .setTextStyle(pos + 2, text.length, textStyle)
        .build()
      ];
    }
    return [SpreadsheetApp.newRichTextValue().setText(text).setTextStyle(a.getTextStyle()).build()];
  });
  range.setRichTextValues(richTextValues);
}

If there is an idea, please provide it. Thanks.

0

There are 0 answers