How to load a specific sheet from a table

I have a table that contains many sheets, and I need to load one of these sheets in my script, how do I do it?

here is a photo of the sheets in my spreadsheet sheets

here is my idea how to do it

var sheet = SpreadsheetApp.openById(index).getSheetByName('Geração de Demanda'); 

- this is?

Thanks.

+10
source share
3 answers

You are almost there ... what you want to make this sheet active, try this:

 var sheet = SpreadsheetApp.getActiveSpreadsheet(); SpreadsheetApp.setActiveSheet(sheet.getSheetByName('Geração de Demanda')) 
+20
source

I know this is an old question. But still ... var ss = SpreadsheetApp.getActiveSpreadsheet ();

var sheet = ss.getSheets () [1];

I think this is the most convenient way, since you do not need to deal with the name, just indicate the sheet number ... [1] indicates the second sheet ... As you can guess, the numbering starts from 0 onwards ...

0
source

I hope you all are well,

You can also create a drop-down list with all sheet names and run the script below to automatically jump to the assigned sheet.

 function goto () { var ss = SpreadsheetApp.getActiveSpreadsheet(); var nameRange = ss.getActiveSheet().getRange(2, 2);//the drop down is in B2 cell var nameValue = nameRange.getValue(); ss.setActiveSheet(ss.getSheetByName(nameValue)); } 

Hope this helps too

Good to you

0
source

All Articles