Return to Snippet

Revision: 67815
at November 1, 2014 18:08 by slvakumr


Updated Code
// Delete all sheets in Google Drive Spreadsheet by name.
// Author : Selva Kumar
// Blog : slvakumr.com
// Date : 30 October 2014

function DeleteAllSheetsInSpreadSheet(name){
  var files = DriveApp.getFilesByType(MimeType.GOOGLE_SHEETS)
  while (files.hasNext()) {
    var file = files.next();
    if (file.getName() == name) {
      var url = file.getUrl();
      var sheet = SpreadsheetApp.openByUrl(url);
      SpreadsheetApp.setActiveSpreadsheet(sheet);
      DeleteAllSheets();
    }
  }
}

// Delete all sheets in active Google Drive Spreadsheet.
// Author : Selva Kumar
// Blog : slvakumr.com
// Date : 30 October 2014

function DeleteAllSheets(){
  var activeSpreadSheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = activeSpreadSheet.getSheets();
  for(var i = 0; i < sheets.length-1; i++) {
    activeSpreadSheet.deleteSheet(sheets[i])
  }
}

Revision: 67814
at October 30, 2014 21:43 by slvakumr


Initial Code
// Delete all sheets in Google Drive Spreadsheet by name.
// Author : Selva Kumar
// Blog : slvakumr.com
// Date : 30 October 2014

function DeleteAllSheetsInSpreadSheet(name){
  var files = DriveApp.getFilesByType(MimeType.GOOGLE_SHEETS)
  while (files.hasNext()) {
    var file = files.next();
    if (file.getName() == name) {
      var url = file.getUrl();
      var sheet = SpreadsheetApp.openByUrl(url);
      SpreadsheetApp.setActiveSpreadsheet(sheet);
      DeleteAllSheets();
    }
  }
}

// Delete all sheets in active Google Drive Spreadsheet.
// Author : Selva Kumar
// Blog : slvakumr.com
// Date : 30 Octber 2014

function DeleteAllSheets(){
  var activeSpreadSheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = activeSpreadSheet.getSheets();
  for(var i = 0; i < sheets.length-1; i++) {
    activeSpreadSheet.deleteSheet(sheets[i])
  }
}

Initial URL

                                

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

Initial Title
Delete all sheets in Google Drive Spreadsheet

Initial Tags
google

Initial Language
C++