Delete all sheets in Google Drive Spreadsheet


/ Published in: C++
Save to your folder(s)

Delete all sheets in a Google Drive Spreadsheet by name/active spreadsheet


Copy this code and paste it in your HTML
  1. // Delete all sheets in Google Drive Spreadsheet by name.
  2. // Author : Selva Kumar
  3. // Blog : slvakumr.com
  4. // Date : 30 October 2014
  5.  
  6. function DeleteAllSheetsInSpreadSheet(name){
  7. var files = DriveApp.getFilesByType(MimeType.GOOGLE_SHEETS)
  8. while (files.hasNext()) {
  9. var file = files.next();
  10. if (file.getName() == name) {
  11. var url = file.getUrl();
  12. var sheet = SpreadsheetApp.openByUrl(url);
  13. SpreadsheetApp.setActiveSpreadsheet(sheet);
  14. DeleteAllSheets();
  15. }
  16. }
  17. }
  18.  
  19. // Delete all sheets in active Google Drive Spreadsheet.
  20. // Author : Selva Kumar
  21. // Blog : slvakumr.com
  22. // Date : 30 October 2014
  23.  
  24. function DeleteAllSheets(){
  25. var activeSpreadSheet = SpreadsheetApp.getActiveSpreadsheet();
  26. var sheets = activeSpreadSheet.getSheets();
  27. for(var i = 0; i < sheets.length-1; i++) {
  28. activeSpreadSheet.deleteSheet(sheets[i])
  29. }
  30. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.