简体   繁体   中英

Google Sheets Scripts - setUnderline not working

I want to make a new text format to a specific cell....A1 in the sheet "Frachtbrief". For the size setFontSize and the Alignment it works very well. But not for the Underline function. I used several writings such as.....nothing works. I always get, that it is not a function....but the syntax is working for the other text formating styles. It is also described herE: https://developers.google.com/apps-script/reference/slides/text-style#setunderlineunderline

  var schreiben7 = sheet3.getRange("A1");
  schreiben7.setValue("Frachtbrief");

  var set=schreiben7.setHorizontalAlignment("center");
  var set=schreiben7.setFontSize("14");
  var set=schreiben7.setUnderline("true");

Any Ideas?

The setUnderline() method you link to is a Slides method. In Sheets, you should use setFontLine() , like this:

  const set = schreiben7
    .setHorizontalAlignment('center')
    .setFontSize(14)
    .setFontLine('underline');

Underline richText

function underlineRichText() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet0");
  const l = sh.getRange(1,1).getDisplayValue();
  const ul = SpreadsheetApp.newTextStyle().setUnderline(true).build();
  const v = SpreadsheetApp.newRichTextValue().setText(l).setTextStyle(0,l.length,ul).build();
  sh.getRange(1,1).setRichTextValue(v);
}

Demo:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM