Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to AutoFit column width with Google Sheets API?

Is there any way to AutoFit Column width in Google Sheets using Google Sheets API? I can find only DimensionProperties but it needs exact value n pixels.

like image 464
GhostKU Avatar asked Apr 22 '18 21:04

GhostKU


1 Answers

You can achieve it using autoResizeDimensions of Sheets API. You can see the detail information at below links.

Endpoint

POST https://sheets.googleapis.com/v4/spreadsheets/### fileId ###:batchUpdate

Request body :

{
  "requests": [
    {
      "autoResizeDimensions": {
        "dimensions": {
          "sheetId": sheetId,
          "dimension": "COLUMNS",
          "startIndex": 0,
          "endIndex": 3
        }
      }
    }
  ]
}

References :

  • sheets.spreadsheets.batchUpdate
  • autoResizeDimensions
  • Sample: Automatically resize a column

If I misunderstand your question, I'm sorry.

like image 136
Tanaike Avatar answered Oct 14 '22 07:10

Tanaike