Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
Pase la variable js en la plantilla html a la secuencia de comandos de Google

Tengo un archivo .gs que crea una página html:

 function doGet() { return HtmlService.createHtmlOutputFromFile('index'); } doGet(); console.log(myvariable);

y en ese archivo index.html crearé una variable en la etiqueta, que me gustaría pasar a mi archivo .gs, para luego colocarlo en la hoja de cálculo de Google.

 <script> var myvariable = 10; </script>

¿Hay algún método que pueda llevar a cabo mi necesidad?

Gracias.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Pasar variable a htmltemplate

 function elfunko() { let t = HtmlService.createTemplate('<input type="text" value="<?= globalvariable ?>" />'); t.globalvariable = "Hello World"; SpreadsheetApp.getUi().showModelessDialog(t.evaluate(),'title'); }

ingrese la descripción de la imagen aquí

Pasar la variable de vuelta al servidor desde html

Este devolverá una variable a los scripts del servidor cuando haga clic en el botón del cuadro de diálogo. Puede ver el resultado mirando el registro de ejecución de elfunko1.

 function elfunko() { let t = HtmlService.createTemplate('<input type="button" value="<?= globalvariable ?>" onclick="google.script.run.elfunko1({variable:<?= globalvariable ?>})" />'); t.globalvariable = "Hello World"; SpreadsheetApp.getUi().showModelessDialog(t.evaluate(),'title'); } function elfunko1(obj) { console.log(JSON.stringify(obj)) }

ingrese la descripción de la imagen aquí

 Cloud logs Feb 26, 2022, 8:38:00 PM Debug {"variable":"Hello World"}

comunicación cliente a servidor

html con plantilla

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!