Google Apps Script Tutorial Part 4 – Hello Everyone, This is 4th post in Google Apps Script Tutorial series and this time I am going to show “How to Write Data in Google Spreadsheet“. In the 3rd post of the series, I have shown how to create UI application in Google Apps Script, this part is the extension of that form. After going through the post, you will be able to call a function when button clicks and eventually write data in Google Spreadsheet.
- How to Use Google Apps Script on Website HTML Pages
- Learn to Send email from Google Apps Script
- Simple Code to Create GUI Application Form in Google Script
How to Write Data in Spreadsheet
You must have remember the ‘Submit’ button created in the earlier post. First you need to open the Google Spreadsheet in Google Script to work with. To do so, use the following methods:
var ss= SpreadsheetApp.openByUrl(“URL_OF_THE_SPREADSHEET”);
var sh=ss. getSheetByName(“SHEET_NAME”);
Second step to Write Data in Google Spreadsheet is to call a function from submit button. This part is very much similar to event handling in Java AWT. To do so, bind the button event with its handler and pass the method name as parameter to call. See the code below:
Third and Final Step is to actually write data into Google Spreadsheet. For this you need to use the following code:
v_name.setValue(“Value to Write”);
Complete Code to Write Data in Google Spreadsheet
Below is the complete code to Write Data into Google Spreadsheet from Google Apps Scripting.
Just try it and if you face any problem, comment below: