英文:
GoogleSheets API does not work. It does not let to strikethrough with API
问题
无法重现问题。
- 创建新的电子表格。
- 获取电子表格ID(https://docs.google.com/spreadsheets/d/1rp11nqj0t0x1111111111111111111111111137Wj4XU/edit#gid=0,在这里是1rp11nqj0t0x1111111111111111111111111137Wj4XU)。
- 用任何内容填充A1:F15范围,例如使用'lorem ipsum'字符串。
- 访问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.
-
Create new Spreadsheet.
-
Take SpreadsheetId (https://docs.google.com/spreadsheets/d/1rp11nqj0t0x1111111111111111111111111137Wj4XU/edit#gid=0, here it is 1rp11nqj0t0x1111111111111111111111111137Wj4XU)
-
Fill range A1:F15 with any content, let's use 'lorem ipsum' string, for instance.
-
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:
-
在您的以下请求体中,
startRowIndex
和endRowIndex
的值相同。因此,此请求体无法正确工作。我认为这可能是您目前问题的原因,即“没有错误,什么都没有发生”。{ "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
andendRowIndex
are the same. By this, this request body cannot be correctly worked. I thought that this might be the reason for your current issue ofNo 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": ###
torange
.###
is the sheet ID.
References:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论