for (var j = 0; j <= buyers.length; j++)
{
var i = 0;
while(i <= products.length)
{
sheet.getRange(i + ((j - 1) * products.length), 1).setValue(buyers[j]);
sheet.getRange(i + ((j - 1) * products.length), 2).setValue(products[i][0]);
}
}
function getDataByName (name){
var source = SpreadsheetApp.openById('1PQp-NwLrnrOZDyJF7FR4');
var sourceNumRows = source.getDataRange().getNumRows();
var sourceValues = source.getDataRange().getValues();
var data = [];
for(var i = 0; i<=sourceNumRows-1; i++)
{
var tgt = name.toLowerCase();
var src = sourceValues[i][1].toString().toLowerCase();
if( tgt == src )
{
var value = [sourceValues[i][1], sourceValues[i][2], sourceValues[i][4], sourceValues[i][7], sourceValues[i][17]];
data.push(value);
}
}
return data;
}
function writeData(source){
var target = SpreadsheetApp.getActiveSheet();
var length = source.length;
target.getDataRange().clear();
for (var i = 0; i <= length-1; i++){
target.getRange(i+1, 1).setValue(source[i][0]);
target.getRange(i+1, 2).setValue(source[i][1]);
target.getRange(i+1, 3).setValue(source[i][2]);
target.getRange(i+1, 4).setValue(source[i][3]);
target.getRange(i+1, 5).setValue(source[i][4]);
}
target.getDataRange().setWrap(true);
}
writeData(getDataByName('Coca-colla'));