I'm currently doing this:
//set active spreadsheet to my template
var ss = SpreadsheetApp.openById("MYSHEETKEY");
SpreadsheetApp.setActiveSpreadsheet(ss);
//duplicate active sheet and set a new name
SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet().setName(rData[0][1]);
which is creating a new sheet in my template Spreadsheet, quite rightly. What I really need is to create an entirely new copy of the document as a whole, ideally in to a specified folder in my Google Drive. Is this possible?
Thanks as advance!
There is a copy() function. The docs are at: https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#copy(String)
var ss = SpreadsheetApp.openById("MYSHEETKEY");
var newSS = ss.copy("Copy of " + ss.getName());
// Move to original folder
var originalFolder = DriveApp.getFileById("MYSHEETKEY").getParents().next();
var newSSFile = DriveApp.getFileById(newSS.getId());
originalFolder.addFile(newSSFile);
DriveApp.getRootFolder().removeFile(newSSFile);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With