Home > Net >  Get row values of spreadsheet, only from specified columns using GAS
Get row values of spreadsheet, only from specified columns using GAS

Time:11-22

Try: Get row values of a spreadsheet. from specified columns

function getAllData() {
var url = 'sheetID';
  var ss= SpreadsheetApp.openByUrl(url);
  var sheet = ss.getSheetByName("Data");  
//var range = sheet.getDataRange() //*This gives all data*

I tried by adding following.

 var rangeList  = sheet.getRangeList(['A1:B', 'E1:F']);     
var values = rangeList.getRanges()
     Logger.log(values)
     return values
    }

data screenshot. But log execution says "Info [Range, Range]" . But I need to display all values of column A, B, E & F in each row.

Please guide me on this.

CodePudding user response:

Just map the one you want:

function lfunko() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet0");
  const vs = sh.getRange(2,1,sh.getLastRow() - 1, sh.getLastColumn()).getValues();
  const o = vs.map(([a,b,,,e,f]) => [a,b,e,f]);
  Logger.log(JSON.stringify(o));
  const osh = ss.getSheetByName("Sheet1");
  osh.clearContents();
  o.unshift(["Product Name","Price1","Price4","UserID"])
  osh.getRange(1,1,o.length,o[0].length).setValues(o);
}
  • Related