Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Created August 31, 2017 04:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tanaikech/d71eaa978d26f649bb1a25c67d279e43 to your computer and use it in GitHub Desktop.
Save tanaikech/d71eaa978d26f649bb1a25c67d279e43 to your computer and use it in GitHub Desktop.
Retrieving Spreadsheet ID from Range using Google Apps Script

Retrieving Spreadsheet ID from Range using Google Apps Script

This is a sample script for retrieving spreadsheet ID from a range using Google Apps Script. I sometimes want to retrieve spreadsheet ID from ranges. In such case, I always use this.

  • Range
  • -> Retrieve Sheet using getSheet()
  • -> Retrieve Spreadsheet using getParent()
  • -> Retrieve spreadsheet ID
var id = "123456789abcdefg";
var sheet = "Sheet";
var cells = "a1:b10";
var range = SpreadsheetApp.openById(id).getSheetByName(sheet).getRange(cells);

var id = range.getSheet().getParent().getId();

>>> id ---> 123456789abcdefg
@Irishgeoff12
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment