Home > Back-end >  List rows that are not empty | appscript
List rows that are not empty | appscript

Time:01-07

To know the last row, you can use getLastRow()

I want something similar...

I need a function to get all non-empty rows

In the table below, for example:

Test
OK
OK
OK
OK

The result I expect is: 1, 3, 4 and 6.

CodePudding user response:

Here is a simple example of how to get non empty row numbers.

function getRows() {
  try {
    let spread = SpreadsheetApp.getActiveSpreadsheet();
    let sheet = spread.getSheetByName("Sheet1");
    let values = sheet.getDataRange().getValues();
    let filled = [];
    // note index is row number -1
    values.forEach( (row,index) => {
        if( row[0] !== "" ) filled.push(index);
      }
    );
    console.log(filled);
  }
  catch(err) {
    console.log(err);
  }
}

Execution log

8:23:45 AM  Notice  Execution started
8:23:47 AM  Info    [ 0, 1, 3, 4, 6 ]
8:23:46 AM  Notice  Execution completed

Reference

  • Related