0
votes

I have a sheet with multiple columns and rows. I want to read data from the sheet by column and not by row. The

sheet.getDataRange().getValues();

function returns an array like this [ row1[column, column..], row2[column, column..]] etc. What I want to do is get an array like: [column1[row, row..], column2[row, row..]] etc.

It's worth to mention that the columns does not have the same number of rows.

Do you guys have any ideas on how to achieve this?

Thanks!

1

1 Answers

4
votes
//* View Logger.log output in the Script Editor View > Logs

function test(a){
  sheet = SpreadsheetApp.getActiveSheet() 
  range = sheet.getDataRange().getValues();
  Logger.log(range);
  transposeRange = Transpose(range);
  Logger.log(transposeRange);
}

function Transpose(a){
  return Object.keys(a[0]).map( function (c) { return a.map(function (r) { return r[c];}); });
}