简体   繁体   English

我想在 Google 工作表上找到第一个空列并将数据粘贴到其中,然后一遍又一遍地做同样的事情

[英]I want to find the first empty column on Google sheet and paste data in it, then do the same thing over and over again

I have multiple sheets, and I want to paste a column of data from a sheet where it get overwritten to a sheet where I can see all the columns next to each other, like an historic.我有多个工作表,我想将一个工作表中的一列数据粘贴到一个工作表中,在那里我可以看到所有相邻的列,就像历史记录一样。

The problem is that my script paste the data in the same column each time.问题是我的脚本每次都将数据粘贴到同一列中。

Here's the script I'm using:这是我正在使用的脚本:

function GraphData() {

  var ss = SpreadsheetApp.getActiveSpreadsheet ();
  var source = ss.getRange("Sheet1!B2:B209");
  var destSheet = ss.getSheetByName("Sheet2");

  var destRange = destSheet.getRange(destSheet.getLastColumn()+1,+2);

  source.copyTo(destRange, {contentsOnly: true});
  source.clear ();

}

Thanks.谢谢。

Issue:问题:

The order of the parameters matters!参数的顺序很重要! On the method getRange(row, column) , the first parameter refers to the row index, and the second to the column index.在方法getRange(row, column)上,第一个参数指的是行索引,第二个参数是列索引。 You have it backwards, so the range is always getting copied to column B.你有它向后,所以范围总是被复制到B列。

Solution:解决方案:

Change the order of the parameters:更改参数的顺序:

var destRange = destSheet.getRange(2, destSheet.getLastColumn() + 1);

Reference:参考:

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

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