Reputation: 1857
I have a spreadsheet with a lot of data. I need to retrieve this data column-wise (or row-wise if column-wise is too complicated). However I can't figure out a way to do this. I have the following working function which returns the data contained in a specific rectangular grid in the spreadsheet specified by row number, column number, number of rows, number of columns.
However, what I want to do, is simply mention the column number and get all the data in that column.
function getSpreadSheetData(){
var id= SpreadsheetApp.getActiveSpreadsheet().getId();
var ss = SpreadsheetApp.openById(id);
var sheets = ss.getSheets();
// the variable sheets is an array of Sheet objects
var sheetData = sheets[0].getRange(row, column, numRows, numColumns);
//consider row,column,numRows,numColumns = 2,1,2,2
return sheetData;
}
How should I modify this code?
Upvotes: 1
Views: 273
Reputation: 10776
How do you want to return it and to what?
it seems what you are trying to achieve can easily be done with:
function getSpreadSheetColumns(sheetName, c){
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
return ss.getRange(1, c, ss.getLastRow()).getValues();
}
Possibly moving the sheet name inside the function if it will always be the same.
Upvotes: 2