简体   繁体   中英

How to retrieve data column-wise in Spreadsheets

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM