简体   繁体   English

如何修复行数不匹配

[英]How to fix number of rows doesn't match

I'm looking for an help in order to fix error:我正在寻求帮助以修复错误:

The number of rows in the data does not match the number of rows in the range数据中的行数与范围内的行数不匹配


var s = SpreadSheetApp.getActive().getActiveSheet();
var file1 = SpreadSheetApp.openById(DriveApp.getFilesByName("test1").next().getId()); // 6000 rows
var file2 = SpreadSheetApp.openById(DriveApp.getFilesByName("test2").next().getId()); // 4000 rows
var file2 = SpreadSheetApp.openById(DriveApp.getFilesByName("test2").next().getId()); // 7000 rows
var files = [file1,file2,file3];
var lastRow = 1;
for (var i = 0; i<=files.length;i++){
   var rangeSource = files[i].getRange("A:AZ").getValues();
   s.getRange("A"+lastRow+":AZ").setValues(rangeSource);
   lastRow = s.getLastRow();
} 

I know that number of row doesn't match, but I'm looking for a tips to avoid this error, without inserting rows in source Data and without using IMPORTRANGE formula in first cell of my current Sheet.我知道行数不匹配,但我正在寻找避免此错误的提示,无需在源数据中插入行,也无需在当前工作表的第一个单元格中使用 IMPORTRANGE 公式。

IF someone has a solution for this type of error, it could be very nice and usefull !如果有人对此类错误有解决方案,那可能会非常好用!

I've already search issues like this but I still don't understand, examples given are too sophisticated for me because I'm newbie in coding.我已经搜索过这样的问题,但我仍然不明白,给出的例子对我来说太复杂了,因为我是编码新手。

Sincerely !真挚地 !

BigBenne大班尼

function myfunc() {
  const tsh = SpreadsheetApp.getActiveSheet();
  var file1 = DriveApp.getFilesByName("test1").next().getId(); // 6000 rows
  var file2 = DriveApp.getFilesByName("test2").next().getId(); // 4000 rows
  var file3 = DriveApp.getFilesByName("test3").next().getId(); // 7000 rows
  var files = [file1, file2, file3];
  var lastRow = 1;
  files.forEach(id=>{
    let ss = SpreadsheetApp.openById(id);
    let sh = ss.getSheets()[0];
    let vs = sh.getRange(1,1,sh.getLastRow(),26).getValues();
    tsh.getRange(tsh.getLastRow() + 1,1,vs.length,vs[0].length).setValues(vs);
  });
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM