0
votes

I have an script that copies an entire Spreadsheet to a new one with a selected name, but I would like to make a loop so I can set a list of all the new spreadsheets that I need to make (10 aprox.)

I already tried to delete the ID sheet from the copied sheet but it didn't worked... So I want the script to use the names on Col A and places the new copy ID on the Col B

function setupSheet() {
var s = SpreadsheetApp.getActive().getSheetByName('ID');
var sheet_name = s.getRange("A1").getValue(); // Get the value of cell A1, used to name the new spreadsheet.
var ID = DriveApp.getFileById("XXXXXXXX").makeCopy(sheet_name, DriveApp.getFolderById("XXXXXXXX")).getId(); //Copies the specific Spreadsheet into an specific folder.
  Logger.log(ID); //Saves the ID of the new Spreadsheet into the Log.
var stringToWrite = Logger.getLog();
SpreadsheetApp.getActive().getActiveSheet().getRange("B1").setValue(stringToWrite); //Writes the ID of the sheet from the Log.
//ID.deleteSheet(ID.getSheetByName('ID')); // remove "ID" sheet which was created by default in new spreadsheet.

}
1

1 Answers

0
votes

We can use JavaScript loops in Google Apps Script like for, do..while, etc. Also we could use Array.protoype.forEach.

To use the names in column A use getValues() to get the values.
To set the names of the copies on column B use setValues().

NOTE: Both of the above methods are methods of Class Range.

For further details, please read https://developers.google.com/apps-script/guides/sheets