如何获得按名称排除某些工作表的工作表数组,即这些工作表而不是此列表中的工作表



我知道如何从电子表格中获取所有表格。电子表格最终会得到越来越多的表格。

const thisDoc = SpreadsheetApp.getActive()
const allSheets = thisDoc.getSheets()

我在电子表格中有两张表的字符串名称列表,我永远不想使用:

excludeList = ["template", "instructions"]

在Python中,我会使用NOT In关键字执行以下操作:

listInclSheets = []
for thisSheet in allSheets:
if sheet.getName() not in excludeList:
listInclSheets.append(thisSheet)

我的问题是:如何使用Array.map((或Array.filter((或其他一些很酷的方法来获得一个数组的子集,该子集不包括基于Google Apps脚本中表的字符串名称列表的成员?

我还知道如何使用嵌套的for循环和布尔标志:

const thisDoc = SpreadsheetApp.getActive()
const arInclSheets = []
const allSheets = thisDoc.getSheets();
excludeList = ["template", "instructions"];
for (thisSheet of allSheets)
{
var booInclude = true;
for (anExcludeName of excludeList)
{
Logger.log("is "+ thisSheet.getName() + "equal to " + anExcludeName +"?");
if (thisSheet.getName() == anExcludeName);
{
booInclude = false; 
}
}
if ( booInclude)
{
arInclSheets.push(thisSheet);
}
}
Logger.log(arInclSheets);
for (thisSheet of arInclSheets)
{
Logger.log(thisSheet.getName());
}
}

带有花哨的单行编码的p.S.地图函数总是让我感到困惑,所以请解释一下,这样我就可以不被它们所迷惑。

按其名称创建排除Setfilter图纸:

const excludeSet = new Set(["template", "instructions"]);
const includedSheets = allSheets.filter(sheet => !excludeSet.has(sheet.getName()))

获取纸张

function one() {
const ss = SpreadsheetApp.getActive();
const excl = ["Sheet0","Sheet1"];
Logger.log(ss.getSheets().filter(sh => !~excl.indexOf(sh.getName())));
}

最新更新