Reputation: 25
Sorry if this is a stupid questions but I was wondering if it is possible to select a specific sheet in a specific spreadsheet and to be able to read it's contents. The script I'm writing will always use values that are stored in a specific sheet.
My problem with SpreadsheetApp.getActiveSpreadsheet()
is it gives you the active spreadsheet and you can do with it as you please but, this means you can only use the active spreadsheet not any others. (Please tell me I'm wrong).
My problem with DriveApp.getFolderById(id)
is that you can't get access to the sheets within the Spreadsheet as it's not in the Spreadsheet format.
Essentially what I'm looking to do is something along the lines of SpreadsheetApp.getSpredsheetById()
if that's possible?
Any help would really be appreciated, and thanks in advance.
Upvotes: 1
Views: 141
Reputation: 1
a good question.... something I've been wondering about also
I think the call ss = SpreadsheetApp.openById("abc1234567"); will bring you the other spreadsheet by ID but you'll need to add the following to identify the specific sheet if it's not the default. setActiveSheet(ss.getSheets()[3])... first sheet is default and id'd as 0 and you'll be OK if there is only one sheet in the other spreadsheet but if you have multiple sheets and aren't using default you'll need the extra code.
Upvotes: 0
Reputation: 3554
You want to use
var ss = SpreadsheetApp.openById("abc1234567");
See information on this on Google's Documentation Page for the SpreadsheetApp Class.
After this you use ss as if you defined it via getActiveSpreadsheet():
var ss = SpreadsheetApp.getActiveSpreadsheet();
Upvotes: 1