这是我正在做的事情(我复制并尝试从旧消息中改编它):
1)在有许多工作表的电子表格中创建一个工作表并将其重命名为“TOC”
2) 在“TOC”中,在 A1 中添加这个公式: =SheetNames( GoogleClock() )
3) 在 Google Apps 脚本中复制后,运行下面的函数“SheetNames”
function SheetNames() { // this will create a list of all the sheets ;)
try {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets()
var out = new Array( sheets.length+1 ) ;
out[0] = [ "Name" , "gid" ];
for (var i = 1 ; i < sheets.length+1 ; i++ ) out[i] = [sheets[i-1].getName() , sheets[i-1].getSheetId() ];
return out
}
catch( err ) {
return "#ERROR!"
}
}
4) 运行函数“delete_only_some_sheets”
function delete_only_some_sheets() {
// CAUTION !! It will delete some sheets !
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getSheetByName("TOC");
for (var i = 3; i<=5; i++){ // !!! HERE adapt the "5" number to your needs here
var tet = source.getRange(["B"]+[(i)]).getValues();
//ss.setActiveSheet(ss.getSheetId()[tet]); ///ERROR here ! ;(
ss.deleteActiveSheet();
//ss.deleteSheetId()[tet]; //possible ??
}
}
我不断收到错误“找不到方法“setActiveSheet(。”)而且我被阻止了。;(
提前谢谢了 ;)
编辑 :
您好,感谢“Srik”,我找到了解决方案!;) 第 1) 到 3) 部分是相同的。第 4 部分)变为:
4) 运行函数“delete_only_some_sheets”
function delete_only_some_sheets() {
// CAUTION !! IT will delete some sheets !
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getSheetByName("TOC");
for (var i = 3; i<=5; i++){ // !!! HERE adapt the "5" number to your needs here
var tet = source.getRange(["A"]+[(i)]).getValues();
ss.setActiveSheet(ss.getSheetByName(tet));
ss.deleteActiveSheet();
}
}