In your situation, I understand as follows.
- There are a lot of rows which are deleted.
- The rows are not continued. So the rows have to be deleted row by row using
deleteRow()
.
If my understanding is correct, how about this modification?
Modification points :
- Use batchUpdate of Sheets API.
- By using Sheets API, the discrete rows can be deleted by one API call.
- Create the list of rows which are deleted as the request body for Sheets API.
- Delete the rows by batchUpdate of Sheets API with the request body.
In order to use Sheets API, please enable Sheets API at Advanced Google Services and API console. About the how to enable them, please check here.
Modified script :
var spreadsheetId = "#####"; // Please input spreadsheet ID.
var sheetId = "#####"; // Please input sheet ID.
var deleteRows = [];
for (var i = values.length - 1; i >= 0; i--) {
if (values[i] == "delete" || values[i] == "") {
deleteRows.push({
"deleteRange": {
"shiftDimension": "ROWS",
"range": {
"startRowIndex": i,
"endRowIndex": i + 1,
"sheetId": sheetId
}
}
});
}
}
Sheets.Spreadsheets.batchUpdate({"requests": deleteRows}, spreadsheetId);
Note :
- In this modified script, it supposes that the retrieved values from Spreadsheet is in
values
.
- Before you run this, please input spreadsheet ID and sheet ID having the rows you want to delete.
If this was not result what you want, I'm sorry.