Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script &引用;范围的坐标或尺寸无效。”;将lastRow用作范围时出错_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script &引用;范围的坐标或尺寸无效。”;将lastRow用作范围时出错

Google apps script &引用;范围的坐标或尺寸无效。”;将lastRow用作范围时出错,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我试图从不同的工作表中复制第一对姓名(A2)和电子邮件(B2),并将它们粘贴到主工作表中 在主工作表中,我需要将它们一个复制到另一个下,因此我考虑使用getlastRow(),在粘贴第一个值后获取第一个空行 此时,即使我在主工作表中没有按特定顺序粘贴值,我也会这样做 当我运行脚本时,出现以下错误-范围的坐标或尺寸无效 我的代码如下 function myFunctions() { var sourceSpreadsheet = SpreadsheetApp.openById(); // sou

我试图从不同的工作表中复制第一对姓名(A2)和电子邮件(B2),并将它们粘贴到主工作表中

在主工作表中,我需要将它们一个复制到另一个下,因此我考虑使用getlastRow(),在粘贴第一个值后获取第一个空行

此时,即使我在主工作表中没有按特定顺序粘贴值,我也会这样做

当我运行脚本时,出现以下错误-范围的坐标或尺寸无效

我的代码如下

function myFunctions() {
 var sourceSpreadsheet = SpreadsheetApp.openById(); // source spreadsheet
 var sheets = sourceSpreadsheet.getSheets(); // array of sheets  

 var targetSpreadSheet = SpreadsheetApp.openById();
 var targetSheet = targetSpreadSheet.getSheetByName('Main'); // 

 for(var i=1; i < sheets.length;i++){  
     var temp = i;
     var tempval = sheets[i].getRange(2,1,1,2).getValues();

     var lastrow = targetSheet.getLastRow();
     var lastcol = targetSheet.getLastColumn();

    targetSheet.getRange(lastrow,1,1,lastcol).setValues(tempval[temp]);
  }

}
函数myFunctions(){
var sourceSpreadsheet=SpreadsheetApp.openById();//源电子表格
var sheets=sourceSpreadsheet.getSheets();//工作表数组
var targetSpreadSheet=SpreadsheetApp.openById();
var targetSheet=targetSpreadSheet.getSheetByName('Main');//
对于(var i=1;i
如果您有任何意见,请与我们分享

提前感谢您的帮助

  • “ts”未定义

  • “tempval”是带有“A2:B2”的二维数组。长度是1。因此,以1开头的“for”循环在数组中显示超出范围

  • 使用“setValues”的数组是二维数组。“tempval[temp]”是一维数组。因此发生了一个错误

  • “getRange”的文档如下所示

  • 尽管如此,也许你想要。“lastrow”和“lastcol”是数据的最后一行和最后一列。因此,数据被覆盖到“targetsheet”的最后一行数据

  • 基于上述内容,修改后的脚本如下所示

    function myFunctions() {
      var sourceSpreadsheet = SpreadsheetApp.openById(); // source spreadsheet
      var sheets = sourceSpreadsheet.getSheets(); // array of sheets  
      var targetSpreadSheet = SpreadsheetApp.openById();
      var targetSheet = targetSpreadSheet.getSheetByName('Main'); // 
      for(var i=1; i < sheets.length;i++){  
        // var temp = i;
        var tempval = sheets[i].getRange(2,1,1,2).getValues();
        var lastrow = targetSheet.getLastRow(); // Is ts targetSheet?
        var lastcol = targetSheet.getLastColumn(); // Is ts targetSheet?
        targetSheet.getRange(lastrow + 1, lastcol + 1, 1, 2).setValues(tempval);
      }
    }
    
    函数myFunctions(){
    var sourceSpreadsheet=SpreadsheetApp.openById();//源电子表格
    var sheets=sourceSpreadsheet.getSheets();//工作表数组
    var targetSpreadSheet=SpreadsheetApp.openById();
    var targetSheet=targetSpreadSheet.getSheetByName('Main');//
    对于(var i=1;i

    我能问一下你想要什么吗?

    嗨,谢谢你的意见。根据你提供的信息,我设法找到了我正在寻找的解决方案。正如我上面所说,我试图从多个工作表中复制相同的值,并将它们添加到主工作表中,一个在另一个下。再次感谢!如果你有什么问题,尽管告诉我。