使用Sheets API调用隐藏列

cha*_*iya 3 google-sheets google-sheets-api

我想通过API v4隐藏google电子表格中的给定列,但是我很难做到这一点。

有谁知道这是否可行并且已经做到了吗?
我们在Apps脚本中有专用的方法来执行此操作,如果REST API中不提供此功能,我会感到惊讶。

pro*_*007 8

就在这里。这不是很简单。

这是隐藏第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()
Run Code Online (Sandbox Code Playgroud)