jueves, 26 de enero de 2023

GAS - How to Create Web App Form on Google Sheets

 

https://codewithcurt.com/how-to-create-web-app-form-on-google-sheets/


How to Create Web App Form on Google Sheets

In this post, I demonstrate how to create a simple Web App form that populates Google Sheets using Google Apps Script.

How to Video:

Video Notes:

  • Legacy Apps Script Editor Used in Video
  • Apps Script (Script Editor) is now located under tab ‘Extensions’ instead of ‘Tools’ on Google Sheets
  • For Further Details on Deploying a Web App Click Here

Code in Video:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
    function AddRow()
    {
      var firstname = document.getElementById("firstname").value;
      var lastname = document.getElementById("lastname").value;
      google.script.run.AddRecord(firstname, lastname);
      document.getElementById("firstname").value = '';
      document.getElementById("lastname").value = '';
    }
    </script>
  </head>
  <body>
    First Name:<input type="text" id="firstname" />
    Second Name:<input type="text" id="lastname" />
    <input type="button" value="Add" onclick="AddRow()" />
  </body>
</html>
function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('WebApp');
}

function AddRecord(firstname, lastname) {
  var url = 'https://docs.google.com/spreadsheets/d/1VBlXysszU9GwwKQ41IuG2-A-Z0SMOr0OVKA-_ACH-P0/edit#gid=0';
  var ss= SpreadsheetApp.openByUrl(url);
  var webAppSheet = ss.getSheetByName("Sheet1");
  webAppSheet.appendRow([firstname, lastname, new Date()]);
  
}

No hay comentarios:

Publicar un comentario