Spreadsheet Service
2 min readMar 1, 2019
App script
This tutorial will help in fetching data from google sheets using the app script.
Using the above sheet, will try to fetch the information in the sheet using app script. Example use case — Get notified when someone submits a google form.
Breakdown:
- SpreadsheetApp service is used here.
- openById will open the sheet (id can be taken from the URL of the sheet).
getSheetByName('sheet_name')
This will select the sheet with the given name. Here ‘tutorial’.
4. Data Range function returns a Range corresponding to the dimensions in which data is present.
5. getValues — returns the rectangular grid of values for this range.
Code:
function services() {var ss = SpreadsheetApp.openById(
‘1XXtDLGCMpS-YBz35lGhalNkNxW_blZPI_JsPE5SGCvo’
); // change the vaue to the sheet ID
var sheet = ss.getSheetByName(‘tutorial’); // default sheet name is ‘Sheet1’
var range = sheet.getDataRange();
var data = range.getValues();
Logger.log(JSON.stringify(data));}
Click on View-> log
Note: This script requires authorisation, which can be given when the script is run for the first time.