2017-11-15 16 views
0

複数のGoogleシート(1つのGoogleシート内)から同じHTMLフォームに動的コンテンツを取得するにはどうすればよいですか?以下のコードでGoogleシートがHTMLフォームを生成していません。

、私は動的にメインシートからHTMLフォームを作成します。補足シートからフォームセレクトを追加したい。私はform.selectを1つのhtml形式の一部にすることはできません。

EDIT:(1)各行にdivを含むようにvar htmlが更新されました。 (2)フォームとテーブルhtmlをhtmlページに直接移動しました。フォームの値はまだ正しく整列されていません。代わりにHTMLテンプレートを使用する必要がありますか?

<head> 
 
    <script type="text/javascript"> 
 
    function setPageValues() { 
 
     //this is working as intended 
 
     google.script.run.withSuccessHandler(displayForm).getValuesFromSS(); 
 
     } 
 
    
 
    function displayForm (values) { 
 
     var colsUsed = [4,5,0,13,15,16,17,18];  //sheet cols for form 
 
     var html = "<form><table border=0 width=90%>"; //start the form 
 
     
 
    //HERE IS THE ISSUE: gets range no problem, but html form is wrong. 
 
    //setting return value "html +=" doesn't work! 
 
google.script.run.withSuccessHandler(displayPick).getValuesForRngName('CategoryRole'); 
 
    
 
    //make the rest of the table (this all works fine) 
 
     for (var j = 0; j < colsUsed.length; j++){ 
 
      colUsed = colsUsed[j] 
 
      html += "<div id=row><tr><th align=right>" + values[0][colUsed] + ":*&nbsp;</th>"; 
 
      html += "<td><input></input type=text></td></tr></div>"; 
 
     } 
 
     
 
     //close out the table and set the value (this all works fine) 
 
     html += "<tr><td></td><td><input type=submit></td></tr></form></table>"; 
 
     html += "<i>* required form data.</i>"; 
 
     document.getElementById("forminfo").innerHTML = html; 
 
    } 
 

 
    //building the pick list works just fine. results not correct in html 
 
    //tried to "return html;" but this didn't work! 
 
    function displayPick (values) { 
 
    var rows = 10000; 
 
    var catUsed = "34-31 21: Supplier"; 
 

 
    //find limit of column values 
 
    for (var i = 0; i < rows; i++) { 
 
     if (values[i] == '') { 
 
     var rows = i; 
 
     break; 
 
     } 
 
    } 
 
    
 
    //build the select field description, and set selected option 
 
    html = "<div id=row><tr><th align=right>" + values[0] + ":*&nbsp;</th><td><select>"; 
 
    for (var i = 1; i < rows; i++) { 
 
     if (values[i] == catUsed) { 
 
     html += "<option selected>" + values[i] + "<option>"; 
 
     } else { 
 
     html += "<option>" + values[i] + "<option>"; 
 
     } 
 
    } 
 
    html += "</select></td></tr></div>"; 
 
    document.getElementById("formpick").innerHTML = html; 
 
    } 
 
    </script> 
 
</head> 
 

 
<body onload="setPageValues()"> 
 
    <form><table border=0 width=90%> 
 
    <div id="formpick"></div> 
 
    <div id="forminfo"></div> 
 
    </table></form> 
 
</body>

答えて

0

"openById" と他のスプレッドシートを開き、プロジェクト内の関数を置きます。その後、google.script.run.withSuccessHandler(functionName)を使用してフォームにデータを返します。

+0

オリジナルの質問を明確にするように更新しました。両方の「シート」が同じ「google spreadsheet」にあります。 1枚のシートには実際のデータがあり、もう1枚には選択可能なリスト値があります。問題はどちらのシートからでもデータを取得することではなく、選択したリストの値を単一のhtml形式で表示することです。 –

関連する問題