Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.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 从一个选项卡复制非空范围,并粘贴到另一个选项卡的末尾,然后将公式向下复制到粘贴范围的右侧_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 从一个选项卡复制非空范围,并粘贴到另一个选项卡的末尾,然后将公式向下复制到粘贴范围的右侧

Google apps script 从一个选项卡复制非空范围,并粘贴到另一个选项卡的末尾,然后将公式向下复制到粘贴范围的右侧,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我使用它将非空单元格从一个选项卡(CopyFromTab)复制到另一个选项卡(PasteToTab)。 但是,当它向粘贴选项卡添加新行时粘贴内容右侧的公式(在粘贴选项卡上)不会向下复制(在粘贴选项卡上)。 是否有方法将公式复制到粘贴选项卡的新行中(需要复制的公式位于使用粘贴内容数据的右侧单元格中) 参考: 这是一个工作脚本:将行添加到粘贴工作表的底部,从工作表中粘贴数据,并向下复制公式。。感谢您的帮助@Stykes function CopyNotEmptyToDifferentTab(){

我使用它将非空单元格从一个选项卡(CopyFromTab)复制到另一个选项卡(PasteToTab)。 但是,当它向粘贴选项卡添加新行时粘贴内容右侧的公式(在粘贴选项卡上)不会向下复制(在粘贴选项卡上)。

是否有方法将公式复制到粘贴选项卡的新行中(需要复制的公式位于使用粘贴内容数据的右侧单元格中)

参考:


这是一个工作脚本:将行添加到粘贴工作表的底部,从工作表中粘贴数据,并向下复制公式。。感谢您的帮助@Stykes

function CopyNotEmptyToDifferentTab(){

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CopyFromTab");  //Copy from here

var range = ss.getRange(8,11,10,6);     //You should be using .getRange(row, column, numRows, numColumns)

  var nonEmpty = range.getValues().filter(function(row) {           // filter matrix for rows
        return row.some(function(col) { // that have at least one column
          return col !== "";});});      // that is not empty

  if (nonEmpty) {


    var sh2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("PasteToTab"); //Paste here
   var lastRowNumber= sh2.getLastRow();  //GETS LAST ROW AS VARIABLE
    sh2.getRange(sh2.getLastRow()+1,1, nonEmpty.length, nonEmpty[0].length).setValues(nonEmpty);

    var sourceRange = sh2.getRange(lastRowNumber,7,1,6);  //You should be using .getRange(row, column, numRows, numColumns)

sourceRange.autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);



  } }
使用:

创建的范围必须包括具有公式的最后一行。对于上面的代码,如果B5中有公式,则此代码将不起作用。相反,范围需要为“B1:B5”或仅为“B5”

使用:


创建的范围必须包括具有公式的最后一行。对于上面的代码,如果B5中有公式,则此代码将不起作用。相反,范围需要是“B1:B5”或只是“B5”

谢谢-我试过了,但没有成功。。。。RangeTopast=sh2.getRange(sh2.getLastRow()+1,1,nonEmpty.length,nonEmpty[0].length);rangeToPaste.setValues(非空);rangeToPaste.autoFillToNeighbor(电子表格应用程序.AutoFillSeries.DEFAULT_SERIES);您收到的错误消息是什么?我认为最后一行代码不应该以“RangeToplaste”开头,这是您刚刚粘贴到的范围。您希望复制下一列中的公式。谢谢,没有错误消息。它只是没有把邻居的公式复制到右边。它会创建新行并将内容粘贴到新行中。它不会复制相邻单元格的公式。e、 g.=iferror(vlookup($I4,'List'!$a2:$M,12,false))应该被复制下来。假设“=iferror(vlookup($I4,'List'!$a2:$M,12,false))”位于单元格B2中。sheet.getRange(“B2”).autoFillToNeighbor(电子表格应用程序.AutoFillSeries.DEFAULT_SERIES);谢谢,我试过这个:sh2.getRange(“H3:R3”).autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);要从H:R中获取公式,请尝试向下复制。。。没有成功。我是不是误解了你的建议?谢谢-我试过了,但没有成功。。。。RangeTopast=sh2.getRange(sh2.getLastRow()+1,1,nonEmpty.length,nonEmpty[0].length);rangeToPaste.setValues(非空);rangeToPaste.autoFillToNeighbor(电子表格应用程序.AutoFillSeries.DEFAULT_SERIES);您收到的错误消息是什么?我认为最后一行代码不应该以“RangeToplaste”开头,这是您刚刚粘贴到的范围。您希望复制下一列中的公式。谢谢,没有错误消息。它只是没有把邻居的公式复制到右边。它会创建新行并将内容粘贴到新行中。它不会复制相邻单元格的公式。e、 g.=iferror(vlookup($I4,'List'!$a2:$M,12,false))应该被复制下来。假设“=iferror(vlookup($I4,'List'!$a2:$M,12,false))”位于单元格B2中。sheet.getRange(“B2”).autoFillToNeighbor(电子表格应用程序.AutoFillSeries.DEFAULT_SERIES);谢谢,我试过这个:sh2.getRange(“H3:R3”).autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);要从H:R中获取公式,请尝试向下复制。。。没有成功。我误解你的建议了吗?你好!你能分享一下这张纸的例子吗?你好!你能分享一下这张纸的例子吗?
function CopyNotEmptyToDifferentTab(){

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CopyFromTab");  //Copy from here

var range = ss.getRange(8,11,10,6);     //You should be using .getRange(row, column, numRows, numColumns)

  var nonEmpty = range.getValues().filter(function(row) {           // filter matrix for rows
        return row.some(function(col) { // that have at least one column
          return col !== "";});});      // that is not empty

  if (nonEmpty) {


    var sh2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("PasteToTab"); //Paste here
   var lastRowNumber= sh2.getLastRow();  //GETS LAST ROW AS VARIABLE
    sh2.getRange(sh2.getLastRow()+1,1, nonEmpty.length, nonEmpty[0].length).setValues(nonEmpty);

    var sourceRange = sh2.getRange(lastRowNumber,7,1,6);  //You should be using .getRange(row, column, numRows, numColumns)

sourceRange.autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);



  } }
   //range you would like to copy down can be one cell or multiple
   var sourceRange = sheet.getRange("B1:B4");

   // Results in B5:whereeverColumnAEnds 
  sourceRange.autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);