function getDetailsForAnId(id='1') {//default used for testing
const ss=SpreadsheetApp.getActive();
const sh=ss.getSheetByName('All Data');
const vs=sh.getRange(2,1,sh.getLastRow()-1,sh.getLastColumn()).getValues();
var oA=[];
oA.push([id].concat(new Array(sh.getLastColumn()-1)));//display id only on first line of each section
vs.forEach(function(r){
if(r[0]==id) {
let t=r.slice();
t[0]='';//remove unnecessary id in output only for clarity
oA.push(t);
}
});
if(oA) {
//console.log(oA);
return oA;
};
}
function loopThruIdsAndDisplayOnOutputSheet() {
const ss=SpreadsheetApp.getActive();
const osh=ss.getSheetByName('OutputSheet');
osh.clearContents();//clear output sheet when starting
const sh=ss.getSheetByName('Filter Data');
const ids=sh.getRange(2,1,sh.getLastRow()-1,1).getValues();
ids.forEach(function(id){
let rows=getDetailsForAnId(id);
if(rows) {
osh.getRange(osh.getLastRow()+1,1,rows.length,rows[0].length).setValues(rows);
}
});
}
所有数据(csv):
COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8,COL9,COL10,COL11,COL12,COL13,COL14,COL15,COL16,COL17,COL18,COL19,COL20,COL21,COL22,COL23,COL24,COL25,COL26
1,0,14,6,0,19,6,24,22,6,4,17,7,15,4,3,16,5,9,8,20,2,9,15,24,12
2,22,15,3,19,22,23,12,9,14,15,7,0,13,8,20,12,20,4,19,18,9,3,3,2,13
3,23,8,20,9,13,19,10,18,24,23,0,17,16,9,9,12,1,24,1,23,6,11,13,3,10
1,11,6,17,0,17,12,12,4,5,6,10,24,22,21,17,11,17,20,18,1,20,7,18,21,9
2,17,12,5,8,24,10,14,13,15,23,21,20,17,9,20,3,16,11,21,23,1,6,23,18,24
3,22,8,24,2,12,22,6,1,5,1,6,2,20,22,1,7,24,23,6,15,19,15,16,19,21
1,3,21,18,24,9,19,3,23,3,10,23,7,14,16,10,7,0,9,14,20,20,15,16,11,11
2,15,13,23,2,11,14,2,6,24,3,16,18,10,10,8,4,1,4,11,7,10,18,17,7,11
3,22,17,19,8,2,13,3,3,21,19,19,3,14,2,11,5,8,22,6,5,1,13,3,4,18
1,13,13,8,22,6,18,14,8,10,1,24,23,12,21,8,19,11,0,4,23,3,22,20,5,5
2,16,16,18,13,9,15,18,12,23,20,17,13,17,8,1,5,5,11,23,12,12,11,21,21,17
3,2,4,17,10,5,18,4,11,7,4,15,1,0,2,11,15,13,20,10,14,22,12,16,12,9
1,12,0,21,2,17,5,1,17,1,12,9,5,9,8,5,18,20,19,14,22,23,11,6,23,7
2,16,2,16,1,9,15,4,20,22,2,19,9,14,10,2,8,6,12,6,15,7,17,21,20,20
3,22,9,16,9,22,10,1,18,16,19,21,13,16,16,18,20,15,5,2,9,16,21,14,7,6
1,20,19,23,18,13,10,13,16,9,23,11,15,20,0,8,18,1,19,2,1,7,7,16,16,11
2,3,12,7,5,6,5,24,19,12,5,20,5,11,10,13,8,1,22,12,16,16,10,8,1,6
3,6,18,18,23,13,22,8,22,4,8,24,2,2,20,13,12,21,12,19,0,1,21,0,24,11
1,15,23,9,1,15,14,5,2,7,0,8,5,6,15,15,10,20,17,9,17,23,17,10,10,11
2,18,22,17,8,9,23,24,0,23,10,10,9,18,10,10,24,16,22,11,11,3,14,9,3,9
3,15,15,17,20,13,12,5,4,21,2,10,10,16,13,19,12,7,2,6,14,13,8,10,16,19
1,12,2,8,11,1,8,24,4,11,19,4,20,20,1,10,22,17,15,7,15,18,24,14,1,21
2,9,9,23,9,11,9,12,15,13,17,14,15,16,13,3,3,15,15,6,2,2,1,18,13,24
3,24,4,23,8,15,1,10,8,7,13,4,19,15,13,23,23,4,20,3,5,11,5,10,7,8
1,3,20,12,4,19,0,20,12,18,1,1,1,10,8,21,18,6,20,15,0,2,4,23,5,22
过滤数据(csv):
HDR1
1
2
3
输出表(csv):
1,,,,,,,,,,,,,,,,,,,,,,,,,
,0,14,6,0,19,6,24,22,6,4,17,7,15,4,3,16,5,9,8,20,2,9,15,24,12
,11,6,17,0,17,12,12,4,5,6,10,24,22,21,17,11,17,20,18,1,20,7,18,21,9
,3,21,18,24,9,19,3,23,3,10,23,7,14,16,10,7,0,9,14,20,20,15,16,11,11
,13,13,8,22,6,18,14,8,10,1,24,23,12,21,8,19,11,0,4,23,3,22,20,5,5
,12,0,21,2,17,5,1,17,1,12,9,5,9,8,5,18,20,19,14,22,23,11,6,23,7
,20,19,23,18,13,10,13,16,9,23,11,15,20,0,8,18,1,19,2,1,7,7,16,16,11
,15,23,9,1,15,14,5,2,7,0,8,5,6,15,15,10,20,17,9,17,23,17,10,10,11
,12,2,8,11,1,8,24,4,11,19,4,20,20,1,10,22,17,15,7,15,18,24,14,1,21
,3,20,12,4,19,0,20,12,18,1,1,1,10,8,21,18,6,20,15,0,2,4,23,5,22
2,,,,,,,,,,,,,,,,,,,,,,,,,
,22,15,3,19,22,23,12,9,14,15,7,0,13,8,20,12,20,4,19,18,9,3,3,2,13
,17,12,5,8,24,10,14,13,15,23,21,20,17,9,20,3,16,11,21,23,1,6,23,18,24
,15,13,23,2,11,14,2,6,24,3,16,18,10,10,8,4,1,4,11,7,10,18,17,7,11
,16,16,18,13,9,15,18,12,23,20,17,13,17,8,1,5,5,11,23,12,12,11,21,21,17
,16,2,16,1,9,15,4,20,22,2,19,9,14,10,2,8,6,12,6,15,7,17,21,20,20
,3,12,7,5,6,5,24,19,12,5,20,5,11,10,13,8,1,22,12,16,16,10,8,1,6
,18,22,17,8,9,23,24,0,23,10,10,9,18,10,10,24,16,22,11,11,3,14,9,3,9
,9,9,23,9,11,9,12,15,13,17,14,15,16,13,3,3,15,15,6,2,2,1,18,13,24
3,,,,,,,,,,,,,,,,,,,,,,,,,
,23,8,20,9,13,19,10,18,24,23,0,17,16,9,9,12,1,24,1,23,6,11,13,3,10
,22,8,24,2,12,22,6,1,5,1,6,2,20,22,1,7,24,23,6,15,19,15,16,19,21
,22,17,19,8,2,13,3,3,21,19,19,3,14,2,11,5,8,22,6,5,1,13,3,4,18
,2,4,17,10,5,18,4,11,7,4,15,1,0,2,11,15,13,20,10,14,22,12,16,12,9
,22,9,16,9,22,10,1,18,16,19,21,13,16,16,18,20,15,5,2,9,16,21,14,7,6
,6,18,18,23,13,22,8,22,4,8,24,2,2,20,13,12,21,12,19,0,1,21,0,24,11
,15,15,17,20,13,12,5,4,21,2,10,10,16,13,19,12,7,2,6,14,13,8,10,16,19
,24,4,23,8,15,1,10,8,7,13,4,19,15,13,23,23,4,20,3,5,11,5,10,7,8|
输出表图像:
顺便说一句,您的问题是如何用一维数组过滤二维数组。您应该知道它们都是二维数组。单列仍然是二维数组。