如何在Apps脚本中引用特定列

时间:2018-12-26 15:42:38

标签: google-apps-script google-sheets

我正在尝试根据条件从工作表中删除行。我发现以下代码可以很好地满足我的需求:

Delete a row in Google Spreadsheets if value of cell in said row is 0 or blank

但是,不清楚如何指定该列。我没看到 e.range.columnStart == 3就像其他答案一样。

有关如何阅读的任何指导?

**
 * Deletes rows in the active spreadsheet that contain 0 or
 * a blank valuein column "C". 
 * For more information on using the Spreadsheet API, see
 * https://developers.google.com/apps-script/service_spreadsheet
 */
function readRows() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange();
  var numRows = rows.getNumRows();
  var values = rows.getValues();

  var rowsDeleted = 0;
  for (var i = 2; i <= numRows - 1; i++) {
    var row = values[i];
    if (row[2] > 1.5 || row[2] < 1) {  
      sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
      rowsDeleted++;
    }
  }
};

0 个答案:

没有答案