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.
To hide columns on Google Sheets Click View > Show Columns, then uncheck any columns that you don't need, then hit OK. Click on the column header on top of the working area to select the column (or columns), you want to hide.
Here's how it's done: Select the headers of the columns you want to hide. Right-click on your selection. Click on 'Hide column(s)' from the context menu that appears.
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()
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