使用Google Sheets API折叠组 [英] Collapsing a group using Google Sheets API

查看:124
本文介绍了使用Google Sheets API折叠组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,作为难以解决的问题,组我正在尝试通过单独调用批处理更新.我可以成功调用请求addDimensionGroup,但是当我请求updateDimensionGroup折叠我刚刚创建的组时,无论是在同一API调用中还是在单独的API调用中,都会出现此错误:

So as a workaround to difficulties creating a new sheet with groups I am trying to create and collapse these groups in a separate call to batchUpdate. I can call request an addDimensionGroup successfully, but when I request updateDimensionGroup to collapse the group I just created, either in the same API call or in a separate one, I get this error:

{
  "error": {
    "code": 400,
    "message": "Invalid requests[1].updateDimensionGroup: dimensionGroup.depth must be \u003e 0",
    "status": "INVALID_ARGUMENT"
  }
}

但是我将深度传递为0,如我在请求中发送的以下JSON所示:

But I'm passing depth as 0 as seen by the following JSON which I send in my request:

{
    "requests":[{
          "addDimensionGroup":{
            "range":{
                "dimension":"ROWS",
                "sheetId":0,
                "startIndex":2,
                "endIndex":5}
            }
        },{
         "updateDimensionGroup":{
           "dimensionGroup":{ 
               "range": {
                   "dimension":"ROWS",
                   "sheetId":0,
                   "startIndex":2,
                   "endIndex":5
               },
               "depth":0,
               "collapsed":true
           },
           "fields":"*"
        }
    }],
    "includeSpreadsheetInResponse":true}',
   ...

我不确定我应该为字段"提供什么,这是

I'm not entirely sure what I am supposed to provide for "fields", the documentation for UpdateDimensionGroupRequest says it is supposed to be a string ("string ( FieldMask format)"), but the FieldMask definition itself shows the possibility of multiple paths, and doesn't tell me how they are supposed to be separated in a single string.

我在做什么错了?

推荐答案

错误消息实际上是在指示您dimensionGroup.depth值必须为> 0:

The error message is actually instructing you that the dimensionGroup.depth value must be > 0:

如果您在工作表上调用spreadsheets.get(),并且仅请求DimensionGroup数据,您会注意到创建的组实际上位于深度1:

If you call spreadsheets.get() on your sheet, and request only the DimensionGroup data, you'll note that your created group is actually at depth 1:

GET https://sheets.googleapis.com/v4/spreadsheets/{SSID}?fields=sheets(rowGroups)&key={API_KEY}

这很有意义,因为深度是(根据API规范):

This makes sense, since the depth is (per API spec):

深度 编号
组的深度,表示有多少个组的范围完全包含该组的范围.

depth number
The depth of the group, representing how many groups have a range that wholly contains the range of this group.

请注意,根据定义,任何给定的特定DimensionGroup完全包含其自己的范围" .

Note that any given particular DimensionGroup "wholly contains its own range" by definition.

如果您的目标是更改DimensionGroup的状态,则需要设置其collapsed属性:

If your goal is to change the status of the DimensionGroup, then you need to set its collapsed property:

{
  "requests": 
  [
    {
      "updateDimensionGroup": 
      {
        "dimensionGroup": 
        {
          "range": 
          {
            "sheetId": <your sheet id>,
            "dimension": "ROWS",
            "startIndex": 2,
            "endIndex": 5
          },
          "collapsed": true,
          "depth": 1
        },
        "fields": "collapsed"
      }
    }
  ]
}

对于此特定 Request ,唯一可以设置的属性是collapsed-其他属性用于标识所需的DimensionGroup进行操作.因此,指定fields: "*"等效于fields: "collapsed".对于大多数请求而言,情况并非如此,因此指定fields: "*"然后省略不需要的请求参数将被解释为从服务器的表示形式中删除缺少的参数".

For this particular Request, the only attribute you can set is collapsed - the other properties are used to identify the desired DimensionGroup to manipulate. Thus, specifying fields: "*" is equivalent to fields: "collapsed". This is not true for the majority of requests, so specifying fields: "*" and then omitting a non-required request parameter is interpreted as "Delete that missing parameter from the server's representation".

要更改DimensionGroupdepth,必须添加或删除包含它的其他DimensionGroup.

To change a DimensionGroup's depth, you must add or remove other DimensionGroups that encompass it.

这篇关于使用Google Sheets API折叠组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆