I tried combining two examples from https://developers.google.com/sheets/api/samples/conditional-formatting
- Read all conditional formats.
- Delete them.
Deletion requires the index to delete, but this is not returned in the read API response. I tried assuming that the index of the returned formats in the array was appropriate, but this encountered an error "no conditional format at index" in the middle of the operation, before they were all deleted.
Here is a copy of the sheet I am trying to clear: https://docs.google.com/spreadsheets/d/1Y0tsEcka-1gziimesE74IhPFqGkUO985eZNoVQ9y0BU/edit#gid=0
How about this solution? In this solution, you problem can be solved by 2 times of API requests.
1. Retrieve all conditional formats from a sheet on Spreadsheet.
sheets.spreadsheets.get
is used for this situation.Request :
Please input
### spreadsheet ID ###
and### sheet name ###
.Response :
This response retrieves the number of conditional formats. This is used for deleting conditional formats.
2. Delete all conditional formats.
sheets.spreadsheets.batchUpdate
is used for this situation.Request :
Request body :
Here,
index
means the number of conditional formats retrieved by aboveGET
method. For example, when there are 2 conditional formats in the sheet, the length ofrequests
is 2. The followingrequests[0]
meanssheets.conditionalFormats[0]
as shown above.Please input
### spreadsheet ID ###
andsheetId
.Note :
References :
If I misunderstand your question, I'm sorry.