[英]Is there a function to exclude certain sheets from my workbook from the script
[英]How to exclude certain sheets from script?
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
}
獲取除某些名稱以外的所有工作表的名稱。 其他代碼正在運行
返回排除數組中未找到的工作表名稱數組。
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
。
這是一個使用 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));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.