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
}
CodePudding user response:
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
}
CodePudding user response:
function sheetNames() {
const exclude = [`Sheet1`, `Sheet2`]
return SpreadsheetApp.getActiveSpreadsheet()
.getSheets()
.map(sheet => sheet.getName())
.filter(sheet => !exclude.includes(sheet))
}