0
votes

I am using the following piece of code in google app scripts to get get data from google spreadsheets. var range1=sheet.getRange("A1:A25").getValues(); I want to set a criteria such that .getValues returns values only if the row contains data , for e.g. if data is present only from A1:A10, then only values from first 10 rows should be returned instead of all 25 rows. Is this possible?

1

1 Answers

0
votes

try:

  1. Define data

  2. Filter it

Sample code:

function GetMyRange() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var range1=sheet.getRange("A1:A25").getValues();
  var range1notNull = notEmpty(range1);

  Logger.log(range1notNull);
}


function notEmpty(dataIn) {
  var dataOut = dataIn.filter(function(item) {
     return (item != '');
  });
  return dataOut;
}

I've found many useful code from here