隐藏所有未在命名范围内列出的工作表

Hide all sheets that are not listed in named range

将我的代码翻译成英文:对于每个 sheet 名称,检查 sheet 名称是否在命名范围“sheetsAlwaysShow”中。如果迭代器 J 到达空白单元格 (""),则需要隐藏 sheet,因为它未在命名范围中列出。这个功能有效。但是有没有更快更有效的方法来解决这个问题?

function hideOtherSheets()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName("Quick Facts");

  var codeNameRange = ss.getRangeByName("sheetsAlwaysShow");
  var codeNameRangeCol = codeNameRange.getColumn();
  
  var sheets = ss.getSheets();

  //var codeNameRange = ss.getRangeByName("participantCodeNameList");

      //Logger.log("Current Cell Value: " + currentCellVal);
        Outer:
        for (i = 0; i < sheets.length; i++) 
        {

          //Logger.log("Current Cell Value: " + currentCellVal);

          Logger.log("Current Sheet: " + sheets[i].getSheetName());
          Inner:
          for (var j =  s.getFrozenRows(); j <= s.getLastRow(); j++)
          {
            
            var currentCellRange = s.getRange(j, codeNameRangeCol);
            var currentCellVal = currentCellRange.getValue().toString();
            var currentSheetName = ss.getSheetByName(currentCellVal);

            Logger.log("Current Sheet Name: " + currentCellVal);
            

            if (currentCellVal != "" || currentCellVal != "" || currentSheetName != null)
            {

              if (sheets[i].getSheetName() == currentCellVal)
              {
                Logger.log("In Iff");
                //sheets[i].hideSheet();
                break Inner;
              }
       
            }
            Logger.log("Current Iteration for J: " + j)

            if (currentCellVal == "")
            {
              Logger.log("Now Hiding: " + sheets[i].getSheetName());
              sheets[i].hideSheet();
              break Inner;
            }

         
            


          }
        }

}

隐藏不在列表中的工作表

function hidesheetsnotinlist() {
  const ss = SpreadsheetApp.getActive();
  const list = ss.getRangeByName("sheetsAlwaysShow").getDisplayValues().flat();//assumed only one column
  ss.getSheets().filter(sh => !~list.indexOf(sh.getName())).forEach(sh => sh.hideSheet());
}

bitwise not