将不连续的选定行从电子表格复制到另一个 [英] Copy not contiguous selected rows from a spreadsheet to another

查看:55
本文介绍了将不连续的选定行从电子表格复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用该脚本可以将所选行从电子表格复制到另一行,从C列复制到E列.电子表格,在H列中显示已复制行的 sent 值.

问题是该脚本采用了连续范围内选择的行,因此没有复制的可能性.连续的选定行.

我该如何解决?

With this script is possible to copy the selected rows from a spreadsheet to another, from the column C to column E.
When the script is terminated, in the "source" spreadsheet, in column H appears the value sent for the rows copied.

The problem is that the script take the rows selected in a contiguous range and so not with the possibility to copy not contiguous selected rows.

How can I solve this?

function main() {

transfer("....", "Foglio1", "Foglio1");

}

function transfer(targetId, sourceSheetName, targetSheetName) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sourceSheet = ss.getSheetByName(sourceSheetName);
  var last = sourceSheet.getActiveRange().getRow();
  var height = sourceSheet.getActiveRange().getHeight();  
  var data = sourceSheet.getRange(last, 3, height, 3).getValues();

  // copy data
  var ss2 = SpreadsheetApp.openById(targetId);
  var targetSheet = ss2.getSheetByName(targetSheetName);
  //get last row
  var lastRow = targetSheet.getLastRow();
  //write data
  targetSheet.getRange(lastRow + 1, 3, data.length, data[0].length)
           .setValues(data);
  
  sourceSheet.getRange(last, 8, height).setValue('Sent');
}

推荐答案

我相信您的目标如下.

  • 您要复制列"C"到"E"使用Google Apps脚本将源工作表中所选行中的选定行转移到目标工作表中.
  • 在复制值时,您想将已发送"的值放在到"H"列;在资料表中.
  • 在您的情况下,选定的行不仅是连续的行,而且还是离散的行.
查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆