'Getting a strange error while trying to build a code formatter inside google sheet api

I have a huge google sheet with some code I'm storing for Blind 75 challenge and I'm trying to add a macro to the sheet so that any coded solution that will be added - it will be highlighted like notepad++ (code blocks is not supported in Google Sheet).

This is the code I was able to write and it covers only the "class" and "def" keywords in python, I'm sorry in advance - it's the first time I'm using the google-sheets-api.This is how my google-sheets looks like

function myFunction() {

    var doc = DocumentApp.create('Test Document');
    var body = doc.getBody();

    var range = SpreadsheetApp.getActiveSheet().getRange("C2:C2");
    var blueColor = SpreadsheetApp.newTextStyle()
      .setForegroundColor("##0303fc")
      .build();
    var purpleColor = SpreadsheetApp.newTextStyle()
      .setForegroundColor("#871f78")
      .build();

    var values = range.getValues();
    for (var i = 0; i < values.length; i++) {
        code_str = values[i]
        const result = code_str.toString().split('\n');
        if (result)
        {
          for (var row = 0; row < result.length; row++) 
          {
            if (result[row].toString().startsWith('class') || result[row].toString().trim().startsWith('def'))
            {
              var changeFunc = SpreadsheetApp.newRichTextValue()
                .setText(result[row])
                .setTextStyle(0, 10, blueColor)
                .build();
            }

            console.log(changeFunc)
            
            range.setRichTextValues([
              [changeFunc]
            ]);
            
          }
        }
    }
}

I'm getting the following error:

Exception: Unexpected error while getting the method or property setRichTextValues on object SpreadsheetApp.Range.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source