Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sheets setUnderline (offsetBegin, offsetEnd)

Does anyone know of a way to underline a portion of text in a Google Sheets cell? I am really looking for a function like my Title to this query.

I have played with .getDisplayValue, .getValue for the Range class and have tried to see if the Doc Text Class might be reachable from Google sheets with no success. I do know I can do this directly from Google Sheets but need to this capability from Google Apps Scripts (GAS).

I also know that this capability in the actual spreadsheet editor is new and may be that the Apps Script needs to catch up.

Thank you for any responses there may be.

Terry

like image 722
TC Lawrence Avatar asked Mar 26 '26 02:03

TC Lawrence


1 Answers

Try the function below for applying underline to your string. Unfortunately, Google Sheets don't seem to support continuous underline.

function underline(string, start, end) {

  start = start || 0;
  end = end || string.length;

  var res = "";

  for (var i=start; i < end; i++) {

    res += string.charAt(i) + "\u0332";

  }

  return res.toString();

}
like image 138
Anton Dementiev Avatar answered Mar 28 '26 02:03

Anton Dementiev