adding variables from google spreadsheet to html template -


i trying push variables spreadsheet fields of html template, other fields of template remain blank user fill in. user can click submit put data spreadsheet.

i have written code below opens user interface , adds new row. first name variable taken data within spreadsheet

here code far....

function onopen() { spreadsheetapp.getui()    .createmenu('dialog')   .additem('open', 'opendialog')   .addtoui(); } function opendialog() {  var html = htmlservice.createhtmloutputfromfile('index')   .setsandboxmode(htmlservice.sandboxmode.iframe);  spreadsheetapp.getui()   .showmodaldialog(html, 'dialog title'); } function getvaluesfromform(form){  var firstname = form.firstname,   lastname = form.lastname,   sheet = spreadsheetapp.getactivespreadsheet().getactivesheet();  sheet.appendrow([firstname, lastname]); } 

here html

<b>add row spreadsheet</b><br />     <form>     first name: <input id= "firstname" name="firstname" type="text" />     last name: <input id="lastname" name="lastname" type="text" />    <input onclick="formsubmit()" type="button" value="add row" />    <input onclick="google.script.host.close()" type="button" value="exit" />    </form>   <script type="text/javascript">     function formsubmit() {         google.script.run.getvaluesfromform(document.forms[0]);     }     </script> 

the issue here not using templated html create output. youre going want take @ this link more information on templated html in apps scripts.

the main difference in code instead of using .createhtmloutputfromfile() create output, need use .createtemplatefromfile() create template, push variables template before evaluating.
apps script code this

var html = htmlservice.createtemplatefromfile('index') html.sheetvalue = valuetobeused //this whatever value want push html spreadsheetapp.getui() .showmodaldialog(html.evaluate().setsandboxmode(htmlservice.sandboxmode.iframe), 'dialog title');

to use value in html, need use called scriplets, allow use apps script code in html file.
this, wherever insert variable pushed html, type . of course, substituting valutobeused variable in both cases.


Comments