App script

This tutorial will help in fetching data from google sheets using the app script.

Image for post
Image for post
Google spreadsheet with sheet name “tutorial”

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:

  1. SpreadsheetApp service is used here.
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

Image for post
Image for post
Log containing the fetched data from our ‘tutorial’ sheet

Note: This script requires authorisation, which can be given when the script is run for the first time.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store