Created
November 13, 2020 17:23
-
-
Save danahmadi/0a1379e41c5a7ae3d7a207c4902ca2f9 to your computer and use it in GitHub Desktop.
Delete Unnamed Filter Views in Google Sheets
This file contains 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
//Drop into script editor and save (update your sheet name in range below) | |
// Make sure to go to Resources/Advanced Google Services/ and enable Google Sheets API access | |
// Then click run in the script editor | |
// Say goodbye to those pesky "Filter 834" views | |
function delete_unnamed_filters() { | |
var substr = "Filter"; | |
var arr_filterViewId = []; | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var id = ss.getId(); | |
var json_obj = Sheets.Spreadsheets.get(id, { | |
ranges: 'Your sheet name goes here', | |
fields: 'sheets/filterViews', | |
}); | |
for(var i = 0; i < json_obj.sheets.length; i++) | |
{ | |
for(var i2 = 0; i2 < json_obj.sheets[i].filterViews.length; i2++) | |
{ | |
var current_filterView = json_obj.sheets[i].filterViews[i2]; | |
var sheetId = current_filterView.range.sheetId; | |
var str_title = current_filterView.title; | |
if(str_title.includes(substr)) | |
{ | |
arr_filterViewId.push(JSON.stringify(current_filterView.filterViewId)); | |
} | |
} | |
} | |
Logger.log(arr_filterViewId); | |
for(var x =0 ; x < arr_filterViewId.length; x++) | |
{ | |
var value_filterId = parseInt(arr_filterViewId[x],10); | |
Sheets.Spreadsheets.batchUpdate({ | |
"requests": [ | |
{ | |
"deleteFilterView": { | |
"filterId": value_filterId | |
} | |
} | |
] | |
},id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment