Reputation: 11
In SpreadSheets, I would like to see a welcome message. I would like to style this message, bold font etc. I try this way, but it doesn't open.
function myFunction() {
const ui = SpreadsheetApp.getUi();
const html = HtmlService.createHtmlOutput('<p>This interface was written in HTML!</p>');
ui.showModalDialog(html, "HTML!");
}
function alertMe() {
return SpreadsheetApp.getUi().alert("You've been alerted!");
}
Upvotes: 0
Views: 1164
Reputation: 11
It should work but your question is not very clear. Also are you calling the alertMe() function. I can see the function definition but not the function call. If you want to format the message you can make a general purpose function e.g.
function showAlert(msg) {
SpreadsheetApp.getUi().alert(msg);
}
Using the word "return" here makes no sense. You can use it later like below:
showAlert ("An error occurred. Please ...");
============ Answer update ========== -- As per the discussion in comments. I noticed that the OP wanted to display a modal dialog on opening the spreadsheet after further research and reading https://developers.google.com/apps-script/reference/script , I came up with the below solution.
function onOpen() {
var sheet = SpreadsheetApp.getActive();
ScriptApp.newTrigger("showStartupMsg")
.forSpreadsheet(sheet)
.onOpen()
.create();
}
function showStyledMsg(msgHTML) {
const ui = SpreadsheetApp.getUi();
const html = HtmlService.createHtmlOutput(msgHTML);
ui.showModalDialog(html, "HTML!");
}
function showStartupMsg() {
showStyledMsg("<p>this is a <b>bold</b> test msg</b>");
}
The above code works for this purpose there is a slight delay in rendering the modal dialog's body but that cannot be helped.
Upvotes: 1