Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setValues cannot convert array to object[][]

i've been coding this on the google apps script for a sheet:

  function basePesa(){
 var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("aux");
  var unique = sheet.getRange("C1").setFormula("=unique(A:A)");
 var Avals = sheet.getRange("C1:C").getValues();
 var Alast = Avals.filter(String).length;
 var transp = sheet.getDataRange().getValues();

 var ss = SpreadsheetApp.openById("14Y3xiAa9kdoK_YO_tAVN-YWC9RE1EANV5wm8Ez1sa1o");
 var base =ss.getSheetByName("Base PESA");
 var values = base.getDataRange().getValues();
 var newdata = new Array(values.length);
 var y = 0;

//  Browser.msgBox(transp.length);

 for(var i=0;i<Alast;i++){


 var tra = Avals[i][0];

 for(var x =1; x<values.length;x++){

 if(values[x][18] == tra){
  newdata[y] = new Array(values[0].length);

 for(var p=0; p<values[0].length;p++)
 newdata[y][p] = values[x][p];   

 y++;
 }

 }   

  }
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Bco de Dados").getRange("A2:AZ"+(y+1)+"").setValues(newdata);
// Browser.msgBox(newdata);


}

It seems that I can't get to write the array into a range. I've checked if the ranges match as well as i'm certain that this array is a 2D one. Any instructions?

Thanks in advance!

like image 281
Lucas Duarte Almeida Avatar asked Mar 09 '23 09:03

Lucas Duarte Almeida


1 Answers

Array 1: [ A , B , C ] <---- Compatible for 1 Row, 3 Columns

Array 2: [ [A] , [B] , [C] ] <--- Compatible for 3 Rows, 1 Column

Array 3: [ [ A , B , C ] , [ A , B , C ] , [ A , B , C ] ] <--- Compatible for 3 Rows , 3 Columns**

**Important to note that the width of each smaller array within the larger array (in this case 3), must be the same for each of the smaller arrays.

Click Here for a Visual Example (Image)

like image 109
user8637437 Avatar answered Mar 31 '23 07:03

user8637437