Here is my situation :
- I have a spreadsheet with values in the 1st column,
- I would like to create a spreadsheet for every value in this file
- and have these files in a specific folder.
My code seems to be working well but crashes after only creating tens of files (I have thousands) Any advice on how to improve that ? I am still pretty new to Google script
//Create files from sheet
function iterateThroughRows() {
var data = SpreadsheetApp.getActive()
var data = sheet.getDataRange().getValues();
data.forEach(function (row) {
var folderId = "MYFOLDERID"
var resource = {
title: row[0], // First Cell/first element of array data
mimeType: MimeType.GOOGLE_SHEETS,
parents: [{ id: folderId }]
}
var fileJson = Drive.Files.insert(resource)
var fileId = fileJson.id
var revisions = Drive.Revisions.list(fileId);
var items = revisions.items;
var revisionId =items[items.length-1].id;
var resource = Drive.Revisions.get(fileId, revisionId);
resource.published = true;
resource.publishAuto = true;
resource.publishedOutsideDomain = true;
Drive.Revisions.update(resource, fileId, revisionId);
});
}