Xav*_*hay 5 google-api google-sheets google-sheets-api google-sheets-conditionalformatting
我尝试结合https://developers.google.com/sheets/api/samples/conditional-formatting 中的两个示例
删除需要删除索引,但这不会在读取 API 响应中返回。我尝试假设数组中返回格式的索引是合适的,但是在操作中间遇到错误“索引处没有条件格式”,然后才将它们全部删除。
这是我要清除的工作表的副本:https : //docs.google.com/spreadsheets/d/1Y0tsEcka-1gziimesE74IhPFqGkUO985eZNoVQ9y0BU/edit#gid=0
这个解决方案怎么样?在此解决方案中,您的问题可以通过 2 次 API 请求来解决。
sheets.spreadsheets.get
用于这种情况。
GET https://sheets.googleapis.com/v4/spreadsheets/### spreadsheet ID ###?ranges=### sheet name ###&fields=sheets%2FconditionalFormats%2Franges%2FsheetId
Run Code Online (Sandbox Code Playgroud)
请输入### spreadsheet ID ###
和### sheet name ###
。
此响应检索条件格式的数量。这用于删除条件格式。
{"sheets": [{"conditionalFormats": [
{"ranges": [{"sheetId": #####}]},
{"ranges": [{"sheetId": #####}]}
]}]}
Run Code Online (Sandbox Code Playgroud)
sheets.spreadsheets.batchUpdate
用于这种情况。
POST https://sheets.googleapis.com/v4/spreadsheets/### spreadsheet ID ###:batchUpdate
Run Code Online (Sandbox Code Playgroud)
这里,index
表示通过上述方法检索到的条件格式的数量GET
。例如,当工作表中有2个条件格式时, 的长度requests
为2。以下requests[0]
含义sheets.conditionalFormats[0]
如上所示。
{"requests": [
{"deleteConditionalFormatRule": {"sheetId": #####, "index": 0}},
{"deleteConditionalFormatRule": {"sheetId": #####, "index": 1}}
]}
Run Code Online (Sandbox Code Playgroud)
请输入### spreadsheet ID ###
和sheetId
。
如果我误解了你的问题,我很抱歉。
归档时间: |
|
查看次数: |
1796 次 |
最近记录: |