Last active
November 17, 2020 15:34
-
-
Save ttsukagoshi/8ffc740ad47fcb4a1b40ff506ee683f8 to your computer and use it in GitHub Desktop.
Delete all sheets in this Google spreadsheet except for the designated sheet IDs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Delete all sheets in this spreadsheet except for the designated sheet IDs | |
* @param {Array} exceptionSheetIds [Optional] Array of sheet IDs to not delete | |
*/ | |
function deleteSheets(exceptionSheetIds) { | |
exceptionSheetIds = exceptionSheetIds || []; | |
const ss = SpreadsheetApp.getActiveSpreadsheet(); | |
const sheets = ss.getSheets(); | |
for (var i = 0; i < sheets.length; i++) { | |
var sheet = sheets[i]; | |
for (var j = 0; j < exceptionSheetIds.length; j++) { | |
var exceptionSheetId = exceptionSheetIds[j]; | |
if (sheet.getSheetId() == exceptionSheetId) { | |
continue; | |
} else { | |
ss.deleteSheet(sheet); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment