Home > Blockchain >  How can I pull an array of sheet names that do not contain a particular term?
How can I pull an array of sheet names that do not contain a particular term?

Time:09-02

The following question/answer appears to answer the question of how to filter a Google Sheets array to those with a particular term in the name:

enter image description here

  • Result

enter image description here

CodePudding user response:

Sheets that do not include a string

function myFunction(s = "ee") {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const allSheets = ss.getSheets().filter(sh => !~sh.getName().indexOf(s));
  const allSheets_names = allSheets.map(sheet => sheet.getSheetName())
  const neededSheets = ["tree"];
  const filteredListOfSheetsNames = []
  neededSheets.forEach(ns =>
    allSheets_names.forEach((as, index) => { if (as.indexOf(ns) > -1) { filteredListOfSheetsNames.push(as) } }))
  const filteredListOfSheets = filteredListOfSheetsNames.map(name => ss.getSheetByName(name))
}

Includes sheets whose names do not include ee

  • Related