Home > Software engineering >  Google Sheet Popup message Function
Google Sheet Popup message Function

Time:12-03

In google sheet i created a custom button and assigned script function showPopup so when i click this button it runs below code and opens a Index.html.

function showPopup(){

  let messagehtml =HtmlService.createHtmlOutputFromFile("index")

  SpreadsheetApp.getUi()

  .showModalDialog(messagehtml , "")

But how to make it open few other html files based on the drop down list by clicking the same button with showPopup function.

Ex. in A5 cell i created a dropdown list Sample 1, Sample 2, Sample 3

So if i select Sample 2 in A5 and if i click same button it should open Index2 html file in popup.

again if i select Sample 3 in A5 and if i click same button it should open Index3 html file in popup

CodePudding user response:

I believe your goal is as follows.

  • You want to use the HTML file by selecting the value at the dropdown list of the cell "A5".

In this case, how about the following sample script?

Sample script:

function showPopup() {
  const sheet = SpreadsheetApp.getActiveSheet();
  if (sheet.getSheetName() != "Sheet1") return; // Please set the sheet name.
  const obj = { "Sample 1": "index1", "Sample 2": "index2", "Sample 3": "index3" };
  const value = sheet.getRange("A5").getValue();
  if (!obj[value]) return;
  let messagehtml = HtmlService.createHtmlOutputFromFile(obj[value]);
  SpreadsheetApp.getUi().showModalDialog(messagehtml, "sample");
}
  • In this script, the value is retrieved from the dropdown list at the cell "A5" and the HTML file is used by the value of the dropdown list.
  • Related