Google apps script 将一堆单页文件编译成大型电子表格的最简单方法是什么?
所以我的问题是,如果我在一个文件夹中有一堆单页google sheets文件,那么最好的脚本方式是如何将所有这些单独的文件表复制到主编译电子表格中,并在其中为每个复制的文件创建一个表?我现在正在为每个文件手动编写它,但我确信有一种更快的方法使用循环,比如[0][1]。。。不同的文件名,但我不知道怎么做。任何帮助都将不胜感激Google apps script 将一堆单页文件编译成大型电子表格的最简单方法是什么?,google-apps-script,google-sheets,google-drive-api,Google Apps Script,Google Sheets,Google Drive Api,所以我的问题是,如果我在一个文件夹中有一堆单页google sheets文件,那么最好的脚本方式是如何将所有这些单独的文件表复制到主编译电子表格中,并在其中为每个复制的文件创建一个表?我现在正在为每个文件手动编写它,但我确信有一种更快的方法使用循环,比如[0][1]。。。不同的文件名,但我不知道怎么做。任何帮助都将不胜感激 function ArrayBuilder() { var filesource = DriveApp.searchFiles('title contains "X"
function ArrayBuilder() {
var filesource = DriveApp.searchFiles('title contains "X" and parents in "File_ID"');
while(filesource.hasNext()){
var File = filesource.next();
var ID = File.getId();
}
var name = File.getName()
var source = SpreadsheetApp.openById(ID);
var sheet = source.getSheets()[0];
var destinationID = "File_ID";
var destination = SpreadsheetApp.openById(destinationID);
sheet.copyTo(destination).setName(name);
var filesource = DriveApp.searchFiles('title contains "Y" and parents in "File_ID"');
while(filesource.hasNext()){
var File = filesource.next();
var ID = File.getId();
}
var name = File.getName()
var source = SpreadsheetApp.openById(ID);
var sheet = source.getSheets()[0];
var destinationID = "File_ID";
var destination = SpreadsheetApp.openById(destinationID);
sheet.copyTo(destination).setName(name);
}
您可以使用以下代码:
var DESTINATION\u电子表格\u ID='';
var PARENT_FOLDER_ID='';
函数buildMasterSpreadsheet(){
var destinationSpreadsheet=SpreadsheetApp.openById(目的地\电子表格\ ID);
var searchQuery=Utilities.formatString(“父文件夹中的“%s”和mimeType='application/vnd.google apps.spreadsheet',父文件夹\u ID);
var sourceFiles=DriveApp.searchFiles(searchQuery);
while(sourceFiles.hasNext()){
var file=sourceFiles.next();
var sourceSheet=SpreadsheetApp.openById(file.getId()).getSheets()[0];
sourceSheet.copyTo(destinationSpreadsheet.setName(file.getName());
}
}
当然,您必须将顶部的变量设置为适当的值。此脚本将:
- 搜索类型为
且父文件夹ID位于其父文件夹中的文件图纸
- 对于找到的每个文件:
- 将其第一张工作表复制到目标电子表格中
您还可以将可能需要的任何其他子句添加到搜索查询中。谢谢您的输入!很抱歉,我不是故意把手动解决方案变成答案来迷惑任何人。对于您的脚本,是否可能有这样一个循环,将搜索参数(title contains)和setname描述符更改为相同的值:即(title包含“Krusty Krab”)……和setname(“Krusty Krab”),但重复一系列常量:Krusty Krab、Chum Bucket等。@WarrenMeroney无需担心。我想知道,如果你有两张被称为“Krusty Krab厨房”和“Krusty Krab大厅”的床单,会发生什么?既然不能有多个具有相同名称的工作表,那么脚本将如何对此作出反应?还是这种情况肯定永远不会发生?干杯