[英]How do I make the variable bold in Google Apps Script?
I want to make bold a string stored in a variable called boldtext.我想将存储在名为 boldtext 的变量中的字符串设为粗体。 I want a simple one line code for this.
我想要一个简单的一行代码。 I am not from coding background.
我不是来自编码背景。 Please help
请帮忙
Edit 1: I made mistake in my original question.编辑 1:我在原来的问题中犯了错误。 So, I am putting the question again.
所以,我再次提出这个问题。
My need = I want variable boldtext to be bold.我的需要 = 我希望变量 boldtext 为粗体。
function calendar() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Course');
var user = Session.getActiveUser().getUsername(); //gives user name
var firstpart = user.split('.')[0]; //gives first part of user name
var uppercase = firstpart.charAt(0).toUpperCase() + firstpart.substring(1);//makes first letter upper case
var boldtext = 'Nice work, ' + uppercase //This has to be made bold
var bold = SpreadsheetApp.newTextStyle().setBold(true).build();
var boldname = SpreadsheetApp.newRichTextValue().setText(boldtext).setTextStyle(boldtext.indexOf(uppercase), boldtext.length, bold).build(); //mistake is here by me.
spreadsheet.getRange('X53').setValue(boldname + 'Reminder is added to your calendar');
function myFunction() {
var user = Session.getActiveUser().getUsername();
var first = user.split('.')[0];
var name = first[0].toUpperCase() + first.substring(1);
var text = 'Nice work, ' + name;
var bold = SpreadsheetApp.newTextStyle().setBold(true).build();
var value = SpreadsheetApp.newRichTextValue().setText(text).setTextStyle(text.indexOf(name), text.length, bold).build();
SpreadsheetApp.getActiveSheet().getRange('A1').setRichTextValue(value);
}
Reference参考
Updated variant更新变体
function calendar() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Course');
var user = Session.getActiveUser().getUsername();
var firstpart = user.split('.')[0];
var name = firstpart[0].toUpperCase() + firstpart.substring(1);
var boldtext = 'Nice work, ' + name;
var bold = SpreadsheetApp.newTextStyle().setBold(true).build();
var text = ' Reminder is added to your calendar';
var value = SpreadsheetApp.newRichTextValue().setText(boldtext + text).setTextStyle(0, boldtext.length, bold).build();
spreadsheet.getRange('X53').setRichTextValue(value);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.