2017-08-22 39 views
0

我在Google工作表中有一些數據。 我如何根據用戶請求提取數據,並根據下拉框生成Google Site。 iam面臨的挑戰。在Google網站中添加下拉框

Prob_1-在谷歌網站

Prob_2-使用下拉框生成從谷歌電子表格谷歌網站的動態數據(或表)。分析_1我做了一個詳細的研究,並明白只有使用第三方插件,我才能做出選擇框。作爲一個新視圖,需要基於此的一些準則。 沒有任何第三方插件是不可能的。

Analysis_2-或者是否有任何其他選項可以根據Google站點中的選擇生成操作。我明白,腳本是不可能在谷歌網站。那麼我該如何做一個按鈕點擊操作。

需要一些指導。

+0

誰告訴腳本是不可能在谷歌的網站? – Ritz

+0

您可以創建一個作爲Web應用程序發佈的Google Apps腳本。然後您使用iFrame顯示發佈的網絡應用程序。請注意,新網站目前可能不支持此功能。在這種情況下,你會鏈接並進入一個新的頁面。由於Web應用程序可以具有HTML和CSS,因此您可以使其看起來像是該網站中的另一個頁面。 –

+0

@Ritz:哦!所以我該如何使用腳本進行動態更改。 Google網站允許按鈕點擊操作? –

回答

1

這是一些JavaScript代碼加載選項到選擇框中。

function updateSelect(vA)//array of values that go into the drop down or select box 
{ 
    var select = document.getElementById("sel1"); 
    select.options.length = 0; 
    for(var i=0;i<vA.length;i++) 
    { 
    select.options[i] = new Option(vA[i],vA[i]); 
    } 
} 

這是選擇框的html。

<select id="sel1" style="width:125px;height:35px;margin:10px 0 10px 0;"> 
     <option value="" selected></option> 
    </select> 

對我來說看起來很簡單。

這是一個更完整的解決方案。

代碼:

function getSelectOptions() 
{ 
    var ss=SpreadsheetApp.getActive(); 
    var sh=ss.getSheetByName('Options'); 
    var rg=sh.getDataRange(); 
    var vA=rg.getValues(); 
    var options=[]; 
    for(var i=0;i<vA.length;i++) 
    { 
    options.push(vA[i][0]); 
    } 
    return vA; 
} 

function showSidebar() 
{ 
    var userInterface=HtmlService.createHtmlOutputFromFile('f'); 
    SpreadsheetApp.getUi().showModelessDialog(userInterface, 'The Drop Down with No Options now has options.'); 
} 

f.html

<!DOCTYPE html> 
<html> 
    <head> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
    <script> 
    $(function() { 
     $('#txt1').val(''); 
     google.script.run 
      .withSuccessHandler(updateSelect) 
      .getSelectOptions(); 
     }); 
    function updateSelect(vA) 
    { 
     var select = document.getElementById("sel1"); 
     select.options.length = 0; 
     for(var i=0;i<vA.length;i++) 
     { 
     select.options[i] = new Option(vA[i],vA[i]); 
     } 
    } 
    console.log("My code"); 
    </script> 
    </head> 
    <body> 
    <select id="sel1" style="width:125px;height:35px;margin:10px 0 10px 0;"> 
    </select> 
</body> 
</html> 

這裏是片命名選項

enter image description here

+0

谷歌腳本里面我們也可以創建這個呢?在腳本標記下 –

+0

是的。我會給你一個完整的谷歌應用程序腳本程序的例子,我每天都會使用,今天晚上有一個動態的下拉菜單。 – Cooper

+0

這非常有幫助。我現在有很大的希望..當我嘗試我得到這個錯誤@Cooper - '腳本功能未找到:doGet' –