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
Javascript 将二维阵列复制到其他图纸 < >我想复制几个2D数组中的单元格的值,它们是在最后一页的中间(由函数生成的,在包含数据的几张纸的帮助下)到另一张表中,在执行这些函数后,将返回这些数据,以避免破坏数据,因为我没有找到./p>的解决方案。_Javascript_Google Apps Script_Google Sheets - Fatal编程技术网

Javascript 将二维阵列复制到其他图纸 < >我想复制几个2D数组中的单元格的值,它们是在最后一页的中间(由函数生成的,在包含数据的几张纸的帮助下)到另一张表中,在执行这些函数后,将返回这些数据,以避免破坏数据,因为我没有找到./p>的解决方案。

Javascript 将二维阵列复制到其他图纸 < >我想复制几个2D数组中的单元格的值,它们是在最后一页的中间(由函数生成的,在包含数据的几张纸的帮助下)到另一张表中,在执行这些函数后,将返回这些数据,以避免破坏数据,因为我没有找到./p>的解决方案。,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,谢谢你的帮助。我不太确定这是否是你想要的,但我在谷歌开发者网站上找到了: var ss = SpreadsheetApp.getActiveSpreadsheet(); var source = ss.getSheets()[0]; var destination = ss.getSheets()[1]; var range = source.getRange("B2:D4"); // This copies the data in B2:D4 in the source sheet to

谢谢你的帮助。

我不太确定这是否是你想要的,但我在谷歌开发者网站上找到了:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getSheets()[0];
var destination = ss.getSheets()[1];

var range = source.getRange("B2:D4");

// This copies the data in B2:D4 in the source sheet to
// D4:F6 in the second sheet
range.copyValuesToRange(destination, 4, 6, 4, 6);


希望这能有所帮助。

我已经列出了一个可能会有所帮助的快速示例。我想找到的示例中的数据是“2b2”,位于四页电子表格的第二页。我想把它所在的栏目复制到第四页。它不漂亮,但很管用。:-)

函数testCopy(){
//获取活动的电子表格
var ss=SpreadsheetApp.getActiveSpreadsheet();
//创建电子表格中所有工作表的数组
var sheets=ss.getSheets();
//声明要将数据复制到的目标工作表
var目的地=表[3];
//为包含我们要复制的数据的工作表创建索引
var targetSheet=0;
//循环检查每个工作表,以检查我们正在查找的数据
对于(变量i=0;i

我不太清楚缩进发生了什么-(

B2:D4它是数组吗?在(ss.getSheets()[0])中,如果我们有她的名字,如何提及该工作表,或者如何获得我们想要的工作表的编号?感谢您的帮助HI arb,使用getRange()只需为任何范围方法设置一个范围引用。下面的代码将创建保存在单元格B2:D4中的数据的2D数组。很抱歉,该代码将是var data=source.getRange('B2:D4').getValues();实际上,我没有常量(在您的示例中为2和4),但它们是可变的,问题在于(“Bvar:Dvar2”)不起作用。@JaySorry在我阅读你的评论之前刚刚发布了这个示例,你可以使用getRange(rowNumber、columnNumber、numberOfRows、numberOfColumns)设置范围,例如B2:D4将是getRange(2、2、3、3),我阅读并重新阅读了你的问题(和另一个问题)但我还是不明白你到底想做什么…当数组的宽度相同时,合并数组并将其写入工作表是非常基本的,是这样吗?
function testCopy() {
  //get the active spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();

 //create an array of all the sheets in our spreadsheet
 var sheets = ss.getSheets();

 // Declare the destination sheet to copy the data to
 var destination = sheets[3];

 //create an index for the sheet that hold the data we want to copy
 var targetSheet = 0;

//loop through each of the sheets to check for the data we are looking for
for (var i = 0; i < sheets.length -1; i++) {

  // Create a 2D array that holds all of the data we want to test from the sheet
  var rowData = sheets[i].getRange('A1:C3').getValues();

  //Loop through each row of data in the 2D array
  for (j = 0; j < rowData.length; j++) {

    // Create an array of the cells in the row
    var cells = rowData[j];

   //loop through each of the cells
   for (k = 0; k < cells.length; k++) {

    // check to see if the cell has the data we are looking for and if so set the   
    // target sheet index to the current sheet
    if (cells[k] == '2b2'){
      targetSheet = i;
    }
   }
  }
}

//set the range of the data we want copy for this example a single column
var copyRange = sheets[targetSheet].getRange('B1:B3');

// copy the data to the destination sheet into D4:D6
copyRange.copyValuesToRange(destination, 4, 4, 4, 6);

}