Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to delete row in googlesheet using googlesheet api v4

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();
    }
}
like image 610
Vinod Verma Avatar asked Aug 26 '16 06:08

Vinod Verma


People also ask

How do I Delete a row in Google Sheets script?

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'.

How do I Delete a row in Google Sheets forever?

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.


1 Answers

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)
    )
  );
like image 94
Eric Koleda Avatar answered Sep 22 '22 10:09

Eric Koleda