How to delete a full column from spreadsheet using Java?

1k views Asked by At

I am building an application by using Google Spreadsheet to store data. I am adding and updating columns dynamically but not getting how to delete a complete column at once!

Could anyone please help me in deleting a column from spreadsheet? I can delete a cell but want to delete all cells which come under a particular column.

Like delete column 'A' and the nearby column 'B' replace column 'A', Like we do by right clicking on a column and select option 'delete column' on drive spreadsheet.

Can anyone help me doing this? Any api or link?

1

There are 1 answers

1
Teyam On

You may want to check rows and columns operations wherein Sheets API allows you to insert, remove and manipulate rows and columns in sheets.

In deleting rows and columns, you may try the sample spreadsheets.batchUpdate request wherein second request deletes columns B:D.

The request protocol is shown below:

POST https://sheets.googleapis.com/v4/spreadsheets/spreadsheetId:batchUpdate


{
  "requests": [
    {
      "deleteDimension": {
        "range": {
          "sheetId": sheetId,
          "dimension": "ROWS",
          "startIndex": 0,
          "endIndex": 3
        }
      }
    },
    {
      "deleteDimension": {
        "range": {
          "sheetId": sheetId,
          "dimension": "COLUMNS",
          "startIndex": 1,
          "endIndex": 4
        }
      }
    },
  ],
}

You may also check Updating Spreadsheets guide for more information on how to implement a batch update in different languages using the Google API client libraries including Java.

Hope that helps!