Is there a way to add and manipulate check boxes in a google sheets using python

Viewed 1144

I need to a way to add, check and uncheck checkboxes in a google sheets sheet via a python api.

Currently I am using Gspread to interact with the sheet however I don't believe that it supports this specific feature. Is there another api I can use that does have this feature, or another way to work around this issue?

2 Answers

Though the answer from @NFR is correct and illustrative, I'll post a more straightforward one.

Some of the formatting options from the API are easily accesible through a helper library: gspread_formatting. Their README has a good description of how it wraps the DATA Validation rules API. To insert checkboxes (having the worksheet already being opened in the usual gspread manner) this snippet will do:

from gspread_formatting import *

validation_rule = DataValidationRule(
    BooleanCondition('BOOLEAN', []), # condition'type' and 'values', defaulting to TRUE/FALSE
    showCustomUi = True
)

set_data_validation_for_cell_range(ws.sheet1, target_range_of_cells, validation_rule)

Hope that helps others like me!

Checkboxes in google sheet uses DATA Validation and are just TRUE/FALSE values. so to check/uncheck all you have to do it set the cell value to TRUE/FALSE. You can use Python with Google Sheets API for it.

https://developers.google.com/sheets/api/quickstart/python
Related