[英]How to make a loop of an Spreadsheet copier (Copies an entire Spreadsheet into a new one with a new name)
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.) 我有一个脚本可以将整个电子表格复制到一个带有选定名称的新电子表格,但我想制作一个循环,这样我就可以设置我需要制作的所有新电子表格的列表(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 我已经尝试从复制的工作表中删除ID表但它没有用...所以我希望脚本使用Col A上的名称并将新的副本ID放在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.
}
We can use JavaScript loops in Google Apps Script like for
, do..while
, etc. Also we could use Array.protoype.forEach
. 我们可以在Google Apps脚本中使用JavaScript循环,例如for
, do..while
等。我们也可以使用Array.protoype.forEach
。
To use the names in column A use getValues()
to get the values. 要使用A列中的名称,请使用getValues()
来获取值。
To set the names of the copies on column B use setValues()
. 要在B列上设置副本的名称,请使用setValues()
。
NOTE: Both of the above methods are methods of Class Range. 注意:上述两种方法都是Class Range的方法。
For further details, please read https://developers.google.com/apps-script/guides/sheets 有关详细信息,请参阅https://developers.google.com/apps-script/guides/sheets
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.