I am looking for a way to remove only formatting on a cell range selection, not their content, using Google sheet API with python.
For now, the only solution I have is to apply the same logic as a normal format and setting the style to NONE. For example, when I set a border format to a specifical range, I use:
request_dict = {'requests': [{
"updateBorders": {
"range": {
"sheetId": sheetId,
"startRowIndex": 1,
"endRowIndex": raws,
"startColumnIndex": first_col,
"endColumnIndex": last_col},
"top": {
"style": "SOLID_MEDIUM",
"width": 1,
"color": {"blue": 0}},
"bottom": {
"style": "SOLID_MEDIUM",
"width": 1,
"color": {"blue": 0}},
"left": {
"style": "SOLID_MEDIUM",
"width": 1,
"color": {"blue": 0}},
"right": {
"style": "SOLID_MEDIUM",
"width": 1,
"color": {"blue": 0}},
"innerHorizontal": {
"style": "SOLID_MEDIUM",
"width": 1,
"color": {"blue": 0}},
"innerVertical": {
"style": "SOLID_MEDIUM",
"width": 1,
"color": {"blue": 0}}}}]}
body = {'requests': request_dict['requests']}
service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId,
body=body).execute()
And if I want to delete it, I replace the "style" field with 'NONE' just like this:
request_dict = {'requests': [{
"updateBorders": {
"range": {
"sheetId": sheetId,
"startRowIndex": 1,
"endRowIndex": raws,
"startColumnIndex": first_col,
"endColumnIndex": last_col},
"top": {
"style": "NONE",
"width": 1,
"color": {"blue": 0}},
"bottom": {
"style": "NONE",
"width": 1,
"color": {"blue": 0}},
"left": {
"style": "NONE",
"width": 1,
"color": {"blue": 0}},
"right": {
"style": "NONE",
"width": 1,
"color": {"blue": 0}},
"innerHorizontal": {
"style": "NONE",
"width": 1,
"color": {"blue": 0}},
"innerVertical": {
"style": "NONE",
"width": 1,
"color": {"blue": 0}}}}]}
body = {'requests': request_dict['requests']}
service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId,
body=body).execute()
But it means I need to define a function to erase format for each kind of format I define, which is not very practical... The first step would be to find a way to erase formatting on a whole sheet, and maybe after to be able to do it for a specifical range in my sheet.