删除选定的行脚本

 收藏

我有此脚本来删除已选中复选框的行。

function deleterows() {
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.showRows(1, sheet.getMaxRows());

  var values = sheet.getRange('K1:K50').getValues();

  values.forEach( function (r, i) {
    Logger.log(r);
    if (r[0]) 
      sheet.deleteRows(i+1);
    }); 
}

But it does not work properly - when I select multiple rows with the checkboxes - it deletes part of selected and part of the rows that follow selection screenshot

我是JavaScript的新手,所以有人可以帮助我吗

回复