function sheetnames() {
var out = new Array()
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var exclude = ["Contractors", "All Group Bids", "About Me","Bid Summary"] // these are the sheet names I do not want
var groupsheets = (sheets != exclude); // I'm not sure if this is formatted properly
for (var i=0 ; i<groupsheets.length ; i++)
{out.push( [ groupsheets[i].getName() ] )}
return out
}
获取所有工作表的名称,但某些名称除外。 other code running
答案 0 :(得分:0)
在排除数组中找不到工作表名称的返回数组。
function sheetNames() {
var out = [];
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var exclude = ["Contractors", "All Group Bids", "About Me", "Bid Summary"];
for (i = 0; i < sheets.length; i++) {
if (exclude.indexOf(sheets[i].getName()) === -1) {
out.push(sheets[i].getName());
}
}
return out;
}
我已经使用array.indexOf()
遍历了工作表数组以比较两者。返回-1
(无匹配项)的任何内容都将添加到数组out
中。
答案 1 :(得分:0)
这里是使用es6 +功能的更简洁版本。这不一定比https://stackoverflow.com/a/57100899/181344更好,但是我总是发现使用命令式循环时更容易出错:
function sheetNames() {
let excluded = ["Contractors", "All Group Bids", "About Me", "Bid Summary"];
return SpreadsheetApp
.getActiveSpreadsheet()
.getSheets()
.filter(s => !excluded.includes(s));
}