How load a specific sheet from a Spreadsheet

2019-04-22 13:24发布

问题:

I have a Spreadsheet that contains a lot of sheets, and i need to load one of these sheets in my script, how i do that?

here is a photo of the sheets in my Spreadsheet

here is my idea how to do it

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

is that?

Thank you.

回答1:

You're almost there... what you want is to make that sheet 'active' so try this :

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


回答2:

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

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

I guess this is the most convenient way, as you dont have to deal with name, just indicate sheet number... [1] indicates second sheet... As you may guess numbering starts from 0 and on...