我想將存盤在一個名為粗體文本的變數中的字串加粗。我想要一個簡單的一行代碼。我不是編碼背景。請幫忙
編輯1: 我在原來的問題中犯了錯誤。所以,我再次提出這個問題。
我的需要=我希望變數粗體為粗體。
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');
uj5u.com熱心網友回復:
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);
}
參考
- 類 RichTextValueBuilder
更新變體
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);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/442356.html
標籤:谷歌应用脚本
