简体   繁体   English

列出不为空的行 | 附加脚本

[英]List rows that are not empty | appscript

To know the last row, you can use getLastRow()要知道最后一行,您可以使用 getLastRow()

I want something similar...我想要类似的东西...

I need a function to get all non-empty rows我需要一个 function 来获取所有非空行

In the table below, for example:例如在下表中:

Test测试
OK好的
OK好的
OK好的
OK好的

The result I expect is: 1, 3, 4 and 6.我期望的结果是:1、3、4 和 6。

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参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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