Dennis
Dennis

Reputation: 67

Archiving specific spreadsheet with Google App Script

I am trying to use Google App Script to archive a spreadsheet in a folder. My spreadsheet has two sheets (named with "Data" and "Current") inside and I want to archive the first sheet "Data" only. Up to now, I tried the following code in Google App Script but it will archive both two sheets. May I know what's wrong with my code? Thank you!

function saveAsSpreadsheet(){ 
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = sheet.getSheetByName('Data!A1:Z1');
  var destFolder = DriveApp.getFolderById("xxxxxxx"); 
  DriveApp.getFileById(sheet.getId()).makeCopy("Archive File", destFolder); 
}

Upvotes: 0

Views: 429

Answers (1)

Eduardo Conte
Eduardo Conte

Reputation: 1203

One possible solution, though it might not be the best (copying useless sheet) is to delete the other sheet in the new created spreadsheet using:

var newFile = DriveApp.getFileById(sheet.getId()).makeCopy("Archive File", destFolder);
var newSs = SpreadsheetApp.open(newFile); 
newSs.deleteSheet(newSs.getSheetByName("Current"));

Upvotes: 1

Related Questions