1

I am using the gspread library in python to send api requests.
The request is to set the dropdown.
However, I could not figure out how to set the following.

  1. set a color for each value in the dropdown
  2. set the display style to "Chip"

cells

Here is the code.

options = ["Apple", "Banana", "Orange"]
values = [{"userEnteredValue": option} for option in options]

request = {
    "requests": [
        {
            "setDataValidation": {
                "range": {
                    "sheetId": 0,
                    "startRowIndex": 1,
                    "endRowIndex": 4,
                    "startColumnIndex": 1,
                    "endColumnIndex": 2,
                },
                "rule": {
                    "condition": {"type": "ONE_OF_LIST", "values": values},
                    "strict": False,
                    "showCustomUi": True
                },
            }
        }
    ]
}

spreadSheet.batch_update(request)

Please let me know if there is a way to do this. Thanks!

karutt
  • 359
  • 1
  • 11

1 Answers1

2

I also wanted to create a "pretty" dropdown by API. But my finding is that API does not support detailed Display Style like "chip" (just True or False on 'showCustomUi' which maps to "Arrow" or "Plain Text".) A formatting property for dropdowns and the choice for the Display Style definitely exists, but it is not visible in the JSON. Hopefully, we can get/set the property in the next API version (v5).

Alternatively, this is not optimal at all, still, I have found it useful that we can COPY the dropdown setting once we create and decorate the dropdown manually, by using "copyPaste" request with "pasteType": "PASTE_DATA_VALIDATION".

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
HJ Han
  • 36
  • 4
  • Welcome to SO! Thank you for you answer. Do you have links to the sources for any of you findings? If so, they might be nice to include, for anyone interested in following up and learning more. Great contribution, looking forward to more of your insights! – SherylHohman Mar 11 '23 at 04:14
  • 1
    Hi @SherylHohman Thank you for pointing out, here is [the link](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#copypasterequest) to the API reference. – HJ Han Apr 11 '23 at 02:35