Share icon

Hello, today we will see how we can upload the data in a Google spreadsheet using Google App script. So let's start

We need to follow the 5 steps for doing that:

Step 1. Create a spreadsheet on Google Spreadsheet, log in to your account, and create a spreadsheet. Once that is done Copy the URL of the spreadsheet from the address bar that we can use in Step 2.

Step 2. Now on the spreadsheet click on Extensions>> Appscript to open the google app script editor here you are able to the code.gs file so copy and paste the below code into that :

let getSheet = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1VFidYhWsdfsdf77rYshIZqz-TfPMsdfX50wE9DCSsdfAWrT4uelftedgh8hoEQk/edit#gid=0")
let sheet = getSheet.getSheetByName("Sheet1");

function doPost(e){
  let data = e.parameters;
  sheet.appendRow([data.first_name[0], data.last_name[0], data.dob[0]]);
  return ContentService.createTextOutput("submitted")
}

Note: you need to Put your Spreadsheet URL

Step 3Now Create the triggers using the left panel 

 

 

Create a new trigger with the following settings, Web app

And Hit Save.

 

Step 4. Now "Deploy", At the top right corner of the page, the Deployment button is there, click on it and choose "New Deployment".

Hit Deploy Button and it will show you the web URL link just like below Image & Copy that URL and we will use that in the next step:

Step 5. Now create an HTML form using the below code and open that page into the browser:

<form method="POST" action="https://script.google.com/macros/s/AKfycbxSjowvhErgstshndfsh79tgV9PW0g8fZFue44zN-5w-wrqc9z7jWdFJCBZW3bd_y5-wKq/exec">
    <input type="text" name="first_name" placeholder="First Name"/>
    <input type="text" name="last_name" placeholder="Last Name"/>
    <input type="text" name="dob" placeholder="DOB"/>
    <input type="submit" value="Submit" />
</form>

Note: use the web app URL that you copied in the last step in action="<your_url>"

Once you HIT the Submit button it will update the data in Spreadsheet that we mention in Step1.

 

Thanks, If you the post do share it with others, 

Happy learning

Add new comment

Restricted HTML