hun*_*188 5 google-sheets google-apps-script
我觉得这应该很简单,但我找不到任何相关内容。我希望我的消息在 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);
}
Run Code Online (Sandbox Code Playgroud)
这bccSendReplace就是我想用逗号解析成新行的内容。相反,代码只是将逗号替换为<br>。我还希望其中的所有文本bccSendReplace都是粗体。有任何想法吗?谢谢!
alert(prompt, buttons)。'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类中的方法。因此,作为一种解决方法,如何通过 Ui 类中的方法使用自定义对话框showModalDialog?当你的脚本被修改后,它会变成如下所示。
请复制并粘贴以下脚本并运行 的功能send。这样,就会打开一个对话框。当单击“确定”按钮和“取消”按钮时,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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2985 次 |
| 最近记录: |