O
O
oe24y2020-09-08 11:42:54
Google Apps Script
oe24y, 2020-09-08 11:42:54

How to Foreach over all Spreadsheets of a Table in Google Script Spreadsheets?

I know how to take only the active sheet
var sheet = SpreadsheetApp.getActive();
And how to do foreach or for on all available sheets?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Stoyanov, 2020-09-08
@oe24y

const sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
  
for(const sheet of sheets) {
  Logger.log(sheet.getName());
}
  
sheets.forEach(function(sheet) {
  Logger.log(sheet.getName());
});
  
while(sheets.length) {
  const sheet = sheets.shift();
    
  Logger.log(sheet.getName());
}

---
Maxim Stoyanov (stomaks), developer of Google Apps Script .
g-apps-script.com
stomaks.me

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question