您的数组是infoData
,它将是这样的:
[
[ A2, B2, C2, D2, E2 ], // infoData[0]
[ A3, B3, C3, D3, E3 ], // infoData[1]
...
[ A22, B2, C22, D22, E22 ] // infoData[20]
]
您的循环j
逐列遍历 infoData[0] 的元素,寻找location
. 这看起来很奇怪。通常,我们希望“记录”位于行中,其值类似于location
出现在特定列中。
如果确实location
是 inA
或数组中的第 0 列,那么您要查找的循环将是:
var newUserInfo = [];
for (var row=0; row<infoData.length; ++row){
if (location == infoData[row][0]);{
// Found matching location; get info for new user
for (var col=1; col<infoData[row].length; ++col) {
newUserInfo.push(infoData[row][col]);
}
break; // Exit after copying the matching row
}
}
if (newUserInfo.length > 0) {
// Now, the newUserInfo array contains the data that was
// to the RIGHT of the location column.
destSheet.getRange(destSheet.lastRow()+1,1,1,newUserInfo.length).setValues([newUserInfo]);
}
编辑:更新的代码......现在,一旦找到匹配的行并将其数据复制到newUserData
被视为数组的 ,搜索将退出。在搜索循环之后,复制的值可用于写入目标工作表 - 在此示例中,假设它们作为新行添加到工作表底部。