I'm using the Google sheets API and have a sheet that I'd like to refresh monthly which would include deleting all the filter views and then recreating them. I know how to create them, but googles example code on deleting them requires you to have a specific ID you want to delete.
I found this other stack overflow question (Mass Delete Filter Views in Google Sheets) but it's not Python so I'm having a hard time understanding how to convert it to Python:
function delFilterViews() {
var ssId = SpreadsheetApp.getActive().getId();
Sheets.Spreadsheets.batchUpdate(
{
requests: Sheets.Spreadsheets.get(ssId, {
ranges: 'Sheet1', //Sheet in which filterviews are present
fields: 'sheets/filterViews/filterViewId',
}).sheets[0].filterViews.map(function(e) {
return { deleteFilterView: { filterId: e['filterViewId'] } }; //create a new delete filter view request for each filter view present in sheet1
}),
},
ssId
);
}
Any suggestions would be appreciated!