Estoy aprendiendo el script de aplicaciones de Google en este momento solo.
He estado tratando de obtener el correo de alguien y adjuntarlo a una hoja de cálculo de Google.
Mi code.gs se ve realmente así:
function doGet() { return HtmlService.createHtmlOutputFromFile("page"); }; function addEmail (mail) { var mysheet = SpreadsheetApp.openById("1k3vWmg9859mYykNNl0xDWoR_LUhnvLlq1qW8kSRuL_Q").getSheetByName("Sheeet1"); mysheet.appendRow(mail); };Y mi archivo html se ve así:
<html> <head> <base target="_top"> </head> <body> <h1>hello</h1> </body> <label for="getUserMail">Type your mail here</label> <input type="text" id="getUserMail"> <button id="trigger">Submit!</button> <script> document.getElementById("trigger").addEventListener("click",sendMailToCode); function sendMailToCode () { var umail = document.getElementById("getUserMail"); google.script.run.addEmail(umail); }; </script> </html>Pero no funciona. Intenté hacer varias cosas para solucionarlo, incluso agregar una etiqueta en html, pero no guarda el valor en la hoja de cálculo. ¿Podría alguien por favor dar un consejo?
Prueba esto:
Esto agregará el html a la hoja pero no lo procesará.
function addEmail (mail='<html><head><basetarget="_top"></head><body><h1>hello</h1></body><labelfor="getUserMail">Typeyourmailhere</label><inputtype="text"id="getUserMail"><buttonid="trigger">Submit!</button><script>document.getElementById("trigger").addEventListener("click",sendMailToCode);functionsendMailToCode(){varumail=document.getElementById("getUserMail");google.script.run.addEmail(umail);};</script></html>') { var ss = SpreadsheetApp.getActive(); const sh = ss.getSheetByName('Sheet0'); sh.appendRow([mail]); }Leyendo la descripción del contenido de la fila: "Una matriz de valores para insertar después de la última fila en la hoja".