在谷歌表中,我創建了一個自定義按鈕并分配了腳本功能,showPopup因此當我單擊此按鈕時,它會在代碼下方運行并打開一個 Index.html。
function showPopup(){
let messagehtml =HtmlService.createHtmlOutputFromFile("index")
SpreadsheetApp.getUi()
.showModalDialog(messagehtml , "")
但是如何通過單擊具有showPopup功能的相同按鈕來根據下拉串列打開其他幾個html檔案。
前任。在 A5 單元格中,我創建了一個下拉串列Sample 1, Sample 2, Sample 3
所以,如果我選擇Sample 2的A5,如果我點擊相同的按鈕應該打開Index2彈出式視窗中的HTML檔案。
再次,如果我選擇Sample 3的A5,如果我點擊相同的按鈕應該打開Index3彈出式視窗中的HTML檔案
uj5u.com熱心網友回復:
我相信你的目標如下。
- 您希望通過選擇單元格“A5”下拉串列中的值來使用 HTML 檔案。
在這種情況下,以下示例腳本如何?
示例腳本:
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");
}
- 在此腳本中,值是從單元格“A5”處的下拉串列中檢索的,并且 HTML 檔案由下拉串列的值使用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/372944.html
下一篇:最新/最大日期值的索引 匹配
