简体   繁体   English

如何制作电子表格复印机的循环(将整个电子表格复制到具有新名称的新电子表格中)

[英]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循环,例如fordo..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.

相关问题 按名称打开电子表格;如果找不到,则创建新的电子表格 - Open spreadsheet by name or create new spreadsheet if none is found 我可以将数据从一个电子表格复制到新的电子表格吗? - Can I copy data from one spreadsheet to a new spreadsheet? 将工作表复制到新电子表格,将单元格值添加到新电子表格名称的末尾 - Copy sheet to new spreadsheet, Add cell value to end of new spreadsheet name 创建新的电子表格,以表格 Google Scripts 的名称命名 - Create new spreadsheet name it by the name of sheet Google Scripts 有没有办法制作电子表格文件的多个副本并在 Google Apps Script 中为每个文件选择名称 - Is there a way to make many copies of a spreadsheet file and choose the name for each file in Google Apps Script 使用数组循环将值与另一个电子表格进行比较并写入新值 - Compare value to another spreadsheet using array loop and write new values 如何制作闭包函数的副本(新实例)? - How to make copies (new instances) of a closure function? 如何在 Node.js 中使用 googleapis 创建新的 Google 电子表格 - How to Create New Google Spreadsheet Using googleapis in Node.js 如何使用javascript添加新的Google电子表格和更新 - How to add new google spreadsheet and update using javascript SlickGrid电子表格。 怎么做? - SlickGrid spreadsheet. How to make?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM