chaiyachaiya
chaiyachaiya

Reputation: 2717

Hide column with Sheets API call

I would like to hide a given column in a google spreadsheet through the API v4, but I struggle to do so.

Does anyone know if it's possible and has managed to do it?
We have in the Apps Script a dedicated method to do so, and I would be surprised if this feature is not available in the REST API.

Upvotes: 6

Views: 5356

Answers (2)

code2bfree
code2bfree

Reputation: 1

I solved this with AI for my use case in MAKE.com

{
"requests": [
  {
    "updateDimensionProperties": {
      "range": {
        "sheetId": "YOUR_SHEET_ID",
        "dimension": "COLUMNS",
        "startIndex": 43,
        "endIndex": 44
      },
      "properties": {
        "hiddenByUser": false
      },
      "fields": "hiddenByUser"
    }
  }
]

}

Hope you enjoy!

Upvotes: 0

propjk007
propjk007

Reputation: 695

Yes, there is. It's just not very straightforward.

Here is an example of hiding column 5:

import httplib2
from apiclient.discovery import build

credentials = get_credentials()  ## See Google's Sheets Docs
http = credentials.authorize(httplib2.Http())

service = build('sheets', 'v4', http=http)

spreadsheet_id = '#####################'
sheet_id = '#######'
requests = []

requests.append({
  'updateDimensionProperties': {
    "range": {
      "sheetId": sheet_id,
      "dimension": 'COLUMNS',
      "startIndex": 4,
      "endIndex": 5,
    },
    "properties": {
      "hiddenByUser": True,
    },
    "fields": 'hiddenByUser',
}})

body = {'requests': requests}
response = service.spreadsheets().batchUpdate(
  spreadsheetId=spreadsheet_id,
  body=body
).execute()

Upvotes: 15

Related Questions