I want to delete a row using rowno in googlesheet using googlesheetv4 api. Can anybody provide me a sample code for this? I have created a method for delete row:
public void deleteRow() {
BatchUpdateSpreadsheetRequest content = new BatchUpdateSpreadsheetRequest();
Request request = new Request();
request.setDeleteDimension(new DeleteDimensionRequest().setRange(new DimensionRange().setDimension("D30:D31")));
List<Request> requests = new ArrayList<Request>();
requests.add(request);
content.setRequests(requests);
System.out.println(content.getRequests());
try {
service.spreadsheets().batchUpdate(IConstant.SPREADSHEET_ID, content);
} catch (IOException e) {
e.printStackTrace();
}
}
Google Apps script function to delete rows based on value in cell. var row = values[i]; if (row[0] == 'delete' || row[0] == '') { // This searches all cells in columns A (change to row[1] for columns B and so on) and deletes row if cell is empty or has value 'delete'.
Delete a Row in Excel and Google Sheets First, we have to select the cell in the row to be deleted and to click on the Delete tab under the section Home-Cells. In Google Sheets, we can delete a row by clicking on the cell in the row to be deleted, right mouse clicking and selecting the option Delete row from the list.
Your code looks close, but you aren't setting up the DimensionRange
correctly. Try the following:
Request request = new Request()
.setDeleteDimension(new DeleteDimensionRequest()
.setRange(new DimensionRange()
.setSheetId(0)
.setDimension("ROWS")
.setStartIndex(30)
.setEndIndex(32)
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With