Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Exclude sheets from list Of Sheet Names With Script

I have found this piece of script that can create a list of all the sheet names in a Google sheet using app script.

But i would like to exclude some of the sheets from the list. For example if i don’t want "Sheet 2" and "Sheet 4" in the list

function sheetnames() { 
  var out = new Array()
  var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
  for (var i=0 ; i<sheets.length ; i++) out.push( [ sheets[i].getName() ] )
  return out  
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Excluded selected sheets

function sheetnames() { 
  var out = new Array()
  var exA = ["Sheet1","Sheet2","Sheet3"];
  var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets().filter(sh => !~exA.indexOf(sh.getName()));
  for (var i=0 ; i<sheets.length ; i++) out.push( [ sheets[i].getName() ] )
  return out  
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading