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

558
Views
¿Cómo puedo leer el contenido de un formulario dentro de una función DoGet()?

Estoy creando un programa de pintura de mapas , que toma datos de X, Y y color de la entrada del usuario y los almacena en una hoja de cálculo de Google .

Los datos se envían a la hoja de cálculo como un formulario, siguiendo esta solución . Cuando se envía el formulario, se envía como una nueva row a la sheet llamada Global . Sin embargo, tengo tres hojas, Global Local y Dungeon y, según las variables contenidas en los datos del formulario que se envían, quiero que la función doGet() en mis hojas de aplicaciones envíe la nueva fila a la hoja correcta.

Aquí está el appScript DoGet() :

 function doGet (e) { const lock = LockService.getScriptLock() lock.tryLock(10000) try { const doc = SpreadsheetApp.openById(scriptProp.getProperty('key')) //++++++++++++++++++SEND TO GLOBAL++++++++++++++++++++++ const Global = doc.getSheetByName("Global") const headers = Global.getRange(1, 1, 1, Global.getLastColumn()).getValues()[0] const nextRow = Global.getLastRow() + 1 const newRow = headers.map(function(header) { //returns a new array, produced by applying a fucntion to every value in an array return header === 'UniqueID' ? new Date() : e.parameter[header] }) Global.getRange(nextRow, 1, 1, newRow.length).setValues([newRow]) //++++++++++++++++++++SEND TO LOCAL++++++++++++++++++++ }

Para aclarar, este código FUNCIONA, pero tengo problemas para decirle QUÉ hoja ( Global Local y Dungeon ) para enviar la nueva fila también. En este momento, todos van a Global. Sin embargo, si tengo un campo en mi formulario que dice Global, Local o Dungeon, ¿cómo puedo hacer que el script de la aplicación lea esto y actúe en consecuencia?

Conceptualmente, necesito referirme a la parte de la matriz de formulario entrante que contiene el nombre de la hoja, y luego puedo escribir el script para usar eso como el nombre de la hoja de esta manera:

const sheetname = doc.getSheetByName("Global/Local/Dungeon")

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

0

Puede usar google.script.run para activar funciones en su secuencia de comandos y pasar valores. Vea este guión revisado.

Formulario de muestra:

muestra

Guion:

 function doGet(e) { return HtmlService.createHtmlOutputFromFile('Index'); } function processData(data) { const lock = LockService.getScriptLock(); lock.tryLock(10000); try { const doc = SpreadsheetApp.openById(ScriptProperties.getProperty('key')); const sheet = doc.getSheetByName(data['sheet']); const headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0]; const nextRow = sheet.getLastRow() + 1; const newRow = headers.map(function(header) { return header === 'timestamp' ? new Date() : data[header]; }); sheet.getRange(nextRow, 1, 1, newRow.length).setValues([newRow]); } catch(e) { } finally { lock.releaseLock(); } }

Índice.html:

 <!DOCTYPE html> <html> <head> <base target="_top"> </head> <body> <form name="submit-to-google-sheet"> <label for="sheet">Sheet:</label><br> <select id="sheet" name="sheet"> <option value="Local">Local</option> <option value="Global">Global</option> <option value="Dungeon">Dungeon</option> </select> <input name="email" type="email" placeholder="Email" required> <input name="firstName" type="text" placeholder="First Name"> <input name="lastName" type="text" placeholder="Last Name"> <button type="submit" onclick="google.script.run.processData(this.form);">Send</button> </form> </body> </html>

Aporte:

aporte

Producción:

producción

about 4 years ago · Juan Pablo Isaza Report

0

Octavia, gracias por la prueba detallada. Sin embargo, la respuesta a mi pregunta fue esta:

const sheet = doc.getSheetByName(e.parameter[sheetName])

Puedo referirme a los datos del formulario entrante usando la sintaxis e.parameter[<column header>]

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!