我觉得这应该很简单,但我什么也找不到。我希望在ui.alert窗口中弹出的消息可以用粗体显示特定的单词,并将,
处的字符串拆分为新的行。下面是我的代码:
function send(){
var ui = SpreadsheetApp.getUi();
var bccSend = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('main_gen').getRange(2,2).getValue(); //value example is xxx@gmail.com, yyy@gmail.com
var bccSendReplace = bccSend.toString().replace(/,/g,"<br>");
var response = ui.alert('You are about to send this to the following email address(es): \n\n' + bccSendReplace + '\n\n Click OK to send, otherwise, close this box or click Cancel to abort.', ui.ButtonSet.OK_CANCEL);
}
bccSendReplace
是我想将逗号解析为新行的内容。相反,代码只是将逗号替换为<br>
。我还希望bccSendReplace
中的所有文本都是粗体。有什么想法吗?谢谢!
发布于 2020-04-09 02:33:48
alert(prompt, buttons)
方法使用HTML标记。'You are about to send this to the following email address(es): \n\n' + bccSendReplace + '\n\n Click OK to send, otherwise, close this box or click Cancel to abort.'
设置为粗体类型。修改点:
alert(prompt, buttons)
方法。因此,作为一种解决办法,如何在类Ui中使用带有showModalDialog
方法的自定义对话框?当您的脚本被修改时,如下所示。
修改脚本:
请复制并粘贴以下脚本并运行send
函数。这样,就打开了一个对话框。单击ok按钮和cancel按钮时,分别运行clickOk()
和clickCancel()
。
function send(){
var ui = SpreadsheetApp.getUi();
var bccSend = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('main_gen').getRange(2,2).getValue();
var bccSendReplace = bccSend.toString().replace(/,/g,"<br>");
const str = 'You are about to send this to the following email address(es): \n\n' + bccSendReplace + '\n\n Click OK to send, otherwise, close this box or click Cancel to abort.';
const html = `
<b>${str}</b><br>
<input type="button" value="ok" onClick="google.script.run.withSuccessHandler(() => google.script.host.close()).clickOk()">
<input type="button" value="cancel" onClick="google.script.run.withSuccessHandler(() => google.script.host.close()).clickCancel()">
`;
ui.showModalDialog(HtmlService.createHtmlOutput(html), 'sample');
}
function clickOk() {
// do something;
}
function clickCancel() {
// do something;
}
注意:
参考文献:
https://stackoverflow.com/questions/61112601
复制相似问题