Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Created August 31, 2017 04:49
Embed
What would you like to do?
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment