Spreadsheet Service

Jibin Jose
Mar 1, 2019 · 2 min read

App script

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

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.
  2. 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

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.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade