Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 465
chaiyachaiya Avatar asked Nov 29 '16 19:11

chaiyachaiya


People also ask

Can you hide a column from view in Google Sheets?

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.

Can you hide a columns in Google Sheets from certain users?

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.


1 Answers

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()
like image 118
propjk007 Avatar answered Sep 28 '22 04:09

propjk007