简体   繁体   English

将文件夹中所有工作表的特定范围内的数据合并到主工作表

[英]Merge data from specific range of all sheets in a folder to a master sheet

Do I have script that I am trying to get a specific range (single row ie AB2:AB10) from each sheet in a folder (getfolderbyid("jkhkkkkkkk") to copy to a specific master sheet getsheetbyID("lklklkjllj")我是否有脚本试图从文件夹中的每个工作表中获取特定范围(单行,即 AB2:AB10)(getfolderbyid("jkhkkkkkkkk") 以复制到特定的主工作表 getsheetbyID("lklklkjllj")

this is what I have but it is looping through all 5000 row of the source data sheet so is very slow /////////////////////////////////////////// function getGaccountsDatafrom() {这就是我所拥有的,但它循环遍历源数据表的所有 5000 行,所以非常慢 //////////////////////// ////////////// function getGaccountsDatafrom() {

var folder = DriveApp.getFolderById("folderID");
 var filesIterator = folder.getFiles();


 *var file;
 var fileType;
 var ssID;
 var combinedData = [];
   var data;
 while(filesIterator.hasNext()){
 file = filesIterator.next();
  fileType = file.getMimeType();  
  if(fileType ==="application/vnd.google-apps.spreadsheet"){
  ssID = file.getId();
  data = getDataFromSpreadsheet(ssID);
 combinedData = combinedData.concat(data);
  } //if end here
 }// while ends here
 var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DATA");
ws.getRange("A2:AQ").clearContent();
ws.getRange(2, 1, combinedData.length, combinedData[0].length).setValues(combinedData);
 }
 function getDataFromSpreadsheet(ssID){
 var ss=SpreadsheetApp.openById(ssID);
 var ws = ss.getSheetByName("DATA");
 var data = ws.getRange("CG3:DW3"+ ws.getLastRow()).getValues();
 return data;
  }////////////////////////////////////////////////////

Hmm... the code is not "looping through all 5000 row of the source data sheet" but iterating files in a folder and getting data from each file separately.嗯...代码不是“循环遍历源数据表的所有 5000 行”,而是迭代文件夹中的文件并分别从每个文件中获取数据。 That is what makes it run slow, and I do not know if it can be made much faster.这就是它运行缓慢的原因,我不知道它是否可以做得更快。

The getDataFromSpreadsheet() function gets too much data because of the superfluous 3 so the result will have blank rows in between. getDataFromSpreadsheet() function 因为多余的3而获取了太多数据,所以结果之间会有空白行。 Here is a quick fix:这是一个快速修复:

  const data = ws.getRange('CG3:DW' + ws.getLastRow()).getValues();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google表格:将文件夹范围导入母版表格 - Google Sheets: Import folder range into Master Sheet 搜索Google应用脚本以迭代工作表文件夹并将一系列数据附加到合并的主工作表中 - Searching for a Google-apps-script to iterate through a folder of sheets and append a range of data to a consolidated master sheet 如何将相同范围从文件夹中的每个文件合并到母版纸上? - How can I merge Same Range from each file in a folder onto a master sheet? 从母版工作表的最后一行复制数据,并将其粘贴到Google工作表中另一工作表的特定单元格 - Copy data from last row of master sheet and paste it in specific cells in another sheet in google sheets 从Google驱动器中可用的所有工作表中复制特定的单元格值,然后使用应用脚本粘贴到主工作表中 - Copy specific cell value from all sheets which are available in the google drive and paste in master sheet with apps script 其他:从子表到主表的不同范围 - Other: Different range into Master Sheet from Child Sheets 如何从一个工作表中复制有效范围并将数据粘贴到Google工作表中同一工作簿中不同工作表中的特定范围内? - How to copy active range from one sheet and pasting the data to a specific range in a different sheet within the same workbook in google sheets? 从母版工作表创建工作表 - Creating sheets with from master sheet 电子表格自动扫描文件夹中的其他工作表并从特定范围导入数据 - Spreadsheet to automatically scan other sheets in a folder and import data from a specific range 将数据从其他多个工作表写入主Google Spreadsheet; 是覆盖每个供稿器表的结果,而不是覆盖所有结果 - Writing data to master Google Spreadsheet from multiple other sheets; am overwriting results of each feeder sheet instead of getting all results
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM