GoogleSheets API不起作用。它不允许使用API添加删除线。

huangapple go评论64阅读模式
英文:

GoogleSheets API does not work. It does not let to strikethrough with API

问题

无法重现问题。

  1. 创建新的电子表格。
  2. 获取电子表格ID(https://docs.google.com/spreadsheets/d/1rp11nqj0t0x1111111111111111111111111137Wj4XU/edit#gid=0,在这里是1rp11nqj0t0x1111111111111111111111111137Wj4XU)。
  3. 用任何内容填充A1:F15范围,例如使用'lorem ipsum'字符串。
  4. 访问https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate。
    4.1 查看右侧,可以找到“尝试此方法”。
    4.2 在“spreadsheetId”字段中填写第2步中获取的ID。
    4.3 填写“请求正文”:

{
"requests": [
{
"repeatCell": {
"cell": {
"userEnteredFormat": {
"textFormat": {
"strikethrough": true
}
}
},
"fields": "*",
"range": {
"startRowIndex": 2,
"endRowIndex": 2,
"startColumnIndex": 1,
"endColumnIndex": 3
}
}
}
]
}

4.4 单击右侧底部的“执行”按钮。
5. 检查您的电子表格。
6. 没有错误,没有任何变化。

我做错了什么?

英文:

One can reproduce the problem.

  1. Create new Spreadsheet.

  2. Take SpreadsheetId (https://docs.google.com/spreadsheets/d/1rp11nqj0t0x1111111111111111111111111137Wj4XU/edit#gid=0, here it is 1rp11nqj0t0x1111111111111111111111111137Wj4XU)

  3. Fill range A1:F15 with any content, let's use 'lorem ipsum' string, for instance.

  4. Visit https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate
    4.1 Look at right side where one can find "Try this method"
    4.2 Fill field "spreadsheetId" with one you've taken on step 2.
    4.3 Fill "Request body" with

    {
    "requests": [
    {
    "repeatCell": {
    "cell": {
    "userEnteredFormat": {
    "textFormat": {
    "strikethrough": true
    }
    }
    },
    "fields": "*",
    "range": {
    "startRowIndex": 2,
    "endRowIndex": 2,
    "startColumnIndex": 1,
    "endColumnIndex": 3
    }
    }
    }
    ]
    }

4.4 Press "Execute" button at the bottom of right side.
5. Check you spreadshet.
6. No error, nothing happened.

What am I doing wrong ?

答案1

得分: 0

Modification points:

  • 在您的以下请求体中,startRowIndexendRowIndex 的值相同。因此,此请求体无法正确工作。我认为这可能是您目前问题的原因,即“没有错误,什么都没有发生”。

    {
       "requests":[
          {
             "repeatCell":{
                "cell":{
                   "userEnteredFormat":{
                      "textFormat":{
                         "strikethrough":true
                      }
                   }
                },
                "fields":"*",
                "range":{
                   "startRowIndex":2,
                   "endRowIndex":2,
                   "startColumnIndex":1,
                   "endColumnIndex":3
                }
             }
          }
       ]
    }
    
  • 此外,在您的请求体中,即使在上述修改反映在其中,单元格的值也会被清除,因为"fields":"*"。请注意这一点。

当这些要点反映在您的请求体中时,以下修改如何?

Modified request body:

{
  "requests": [
    {
      "repeatCell": {
        "cell": {
          "userEnteredFormat": {
            "textFormat": {
              "strikethrough": true
            }
          }
        },
        "fields": "userEnteredFormat.textFormat.strikethrough",
        "range": {
          "startRowIndex": 0,
          "endRowIndex": 15,
          "startColumnIndex": 0,
          "endColumnIndex": 6,
        }
      }
    }
  ]
}
}
  • 在这个修改后的请求体中,从在范围A1:F15填充任何内容,例如使用'lorem ipsum'字符串,单元格"A1:F15"被使用。因此,strikethrough 用于这些单元格。

  • 在您的请求体中,未使用 sheetId。因此,在这种情况下,将使用Google电子表格中的第一个标签页。请注意这一点。如果您想要将其用于特定标签页,请将 "sheetId": ### 属性添加到 range### 是标签页的 ID。

References:

英文:

Modification points:

  • In your following request body, the values of startRowIndex and endRowIndex are the same. By this, this request body cannot be correctly worked. I thought that this might be the reason for your current issue of No error, nothing happened..

    {
       "requests":[
          {
             "repeatCell":{
                "cell":{
                   "userEnteredFormat":{
                      "textFormat":{
                         "strikethrough":true
                      }
                   }
                },
                "fields":"*",
                "range":{
                   "startRowIndex":2,
                   "endRowIndex":2,
                   "startColumnIndex":1,
                   "endColumnIndex":3
                }
             }
          }
       ]
    }
    
  • And also, in your request body, even when the above modification is reflected, the cell values are cleared by "fields":"*". Please be careful about this.

When these points are reflected in your request body, how about the following modification?

Modified request body:

{
  "requests": [
    {
      "repeatCell": {
        "cell": {
          "userEnteredFormat": {
            "textFormat": {
              "strikethrough": true
            }
          }
        },
        "fields": "userEnteredFormat.textFormat.strikethrough",
        "range": {
          "startRowIndex": 0,
          "endRowIndex": 15,
          "startColumnIndex": 0,
          "endColumnIndex": 6,
        }
      }
    }
  ]
}
  • In this modified request body, from Fill range A1:F15 with any content, let's use 'lorem ipsum' string, for instance., the cells "A1:F15" are used. So, strikethrough is used for these cells.

  • In your request body, sheetId is not used. So, in this case, the 1st tab in Google Spreadsheet is used. Please be careful about this. If you want to use it for the specific sheet, please add the property of "sheetId": ### to range. ### is the sheet ID.

References:

huangapple
  • 本文由 发表于 2023年2月10日 06:10:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404966.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定