将2D数组复制到另一个工作表
Copy 2D array to another sheet
我想从几个2D数组中复制单元格的值,这些值位于最终工作表的中间(由一个函数生成,在几个包含数据的工作表的帮助下)到另一个工作表,该工作表将在执行函数后返回该数据,以避免粉碎数据,因为我没有找到我最后一个问题的解决方案。
谢谢你的帮助。
不太确定这是不是你想要的,但我在谷歌开发者网站上发现了这个:
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);
https://developers.google.com/apps-script/reference/spreadsheet/range copyValuesToRange(表,整数,整数,整数,整数)
我整理了一个快速示例,可能会有所帮助。我要查找的示例中的数据是位于四表电子表格的第二页中的"2b2"。我想把它所在的那一栏复制到第4页。虽然不好看,但效果不错。: -)
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);
}
我不太清楚缩进是怎么回事。: - (
相关文章:
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 我的shareService在angular 2中发送值工作正常,但当我渲染我的另一个组件时,会获得默认值
- DIV怎么能像Javascript中的另一个元素一样工作呢
- 当单元格内容由于forumula从另一个工作表编译数据而更改时发送电子邮件
- jQuery点击()事件在另一个点击()中获胜'我不能在手机上工作
- 在页面中使用了两次多个图像上传,但第一个正在工作,另一个不起作用
- 将搜索按钮从一个站点复制到另一个站点:此搜索按钮如何工作,以及如何重现其操作
- 另一个 ng-click() 未按预期工作
- 一个对象怎么能像返回自身和另一个对象一样工作
- 另一个按钮内的按钮不会;不能在Firefox(Angular Material)中工作
- 由于另一个干扰函数,Javascript函数无法正常工作
- 将数据从一个工作表复制到另一个工作表;使用目标工作表中的复制数据创建一个表
- 即使我从另一个工作小提琴复制代码,JSFiddle 也不起作用
- 根据条件将行从一个工作表复制到另一个工作表
- 如何在不移动过滤功能的情况下将一组过滤后的数据移动到另一个工作表
- 将2D数组复制到另一个工作表
- 如何编写一个脚本,清除所需工作表(其名称在另一个工作表的单元格中指定)的(所有)内容
- 复制&在复制到另一个工作表时,修改每个表单提交的特定值
- 在Google Sheets中按列名从一个工作表提取单元格值到另一个工作表
- 将行有条件地复制到另一个工作表,并在行更新后删除它们