I created a google sheet template and then we created almost 200 sheets from that template, now we updated the original template, and I am trying to figure out a way to updated the 200 files without losing the data.
What I did so far is create the script below to create a new file from updated template with the same filename and save it to the same folder as the old file but it fails to delete the old file, I get an error saying:
Exception: Access denied: DriveApp
I have to note the files are created by different users, so if that is the reason of the access denial, is there's a way around it??
Any idea how to solve this??
function createNewAndCopy() {
var ss = SpreadsheetApp.openById("template ID");
var sss = SpreadsheetApp.getActiveSpreadsheet();
var newSS = ss.copy(sss.getName());
// Move to original folder
var originalFolder = DriveApp.getFileById(sss.getId()).getParents().next();
var newSSFile = DriveApp.getFileById(newSS.getId());
originalFolder.addFile(newSSFile);
DriveApp.getRootFolder().removeFile(newSSFile);
var sheetmed = SpreadsheetApp.getActive().getSheetByName('Start here');
var sheet = SpreadsheetApp.openById(newSS.getId()).getSheetByName('Start here');
var range = sheetmed.getRange("A6:D55");
values = range.getValues();
var ssRange = sheet.getRange("A6:D55");
ssRange.setValues(values);
var range2 = sheetmed.getRange("B1:L2");
values2 = range2.getValues();
var ssRange2 = sheet.getRange("B1:L2");
ssRange2.setValues(values2);
var ssss = SpreadsheetApp.getActiveSpreadsheet();
//DriveApp.getFilesByName(ssss.getName()).setTrashed(true);
DriveApp.getFileById(ssss.getId()).setTrashed(true);
}
I'd really appreciate the help
setFormula(formula)
Doc ref