Home > front end >  Delete type “one of the list” using googlesheet api v4
Delete type “one of the list” using googlesheet api v4

Time:05-27

I use POST, for added list in my sheets, but I can’t delete this rule from sheets. Tell me please, how I can use POST for remove this rule?

{
  "setDataValidation": {
    "range": {
      "sheetId": sheet_id,
      "startRowIndex": 1,
      "endRowIndex": 1,
      "startColumnIndex": 22,
      "endColumnIndex": 23
    },
    "rule": {
      "condition": {
        "type": 'ONE_OF_LIST',
        "values": [
          {
          "userEnteredValue": 'YES',
          },
          {
          "userEnteredValue": 'NO',
          },
          {
          "userEnteredValue": 'MAYBE',
          },
        ],
      },
      "showCustomUi": True,
      "strict": True
    }
  }
}

CodePudding user response:

I believe your goal is as follows.

  • You want to remove one of the items from the list of the data validation rule.
  • You want to remove the data validation rule.

1. Create a data validation rule.

I think that your request body doesn't create the data validation. Because the values of startRowIndex and endRowIndex are the same. So, for example, it supposes that a data validation rule is created by the following request. The data validation rule is created for cell "A1".

{
  "setDataValidation": {
    "range": {
      "sheetId": 0,
      "startRowIndex": 0,
      "endRowIndex": 1,
      "startColumnIndex": 0,
      "endColumnIndex": 1
    },
    "rule": {
      "condition": {
        "type": "ONE_OF_LIST",
        "values": [
          {
          "userEnteredValue": "YES",
          },
          {
          "userEnteredValue": "NO",
          },
          {
          "userEnteredValue": "MAYBE",
          },
        ],
      },
      "showCustomUi": true,
      "strict": true
    }
  }
}

2. Remove one of the items from the data validation rule.

For the data validation rule created by the above request, if you want to remove one of the items, how about the following request? In this request, the item of MAYBE is removed from the data validation rule of the cell "A1".

{
  "setDataValidation": {
    "range": {
      "sheetId": 0,
      "startRowIndex": 0,
      "endRowIndex": 1,
      "startColumnIndex": 0,
      "endColumnIndex": 1
    },
    "rule": {
      "condition": {
        "type": "ONE_OF_LIST",
        "values": [
          {
          "userEnteredValue": "YES",
          },
          {
          "userEnteredValue": "NO",
          },
        ],
      },
      "showCustomUi": true,
      "strict": true
    }
  }
}

3. Remove data validation rule.

If you want to remove the data validation rule of the cell "A1", how about the following request? In this request, the data validation rule of the cell "A1" is removed.

{
  "updateCells": {
    "range": {
      "sheetId": 0,
      "startRowIndex": 0,
      "endRowIndex": 1,
      "startColumnIndex": 0,
      "endColumnIndex": 1
    },
    "fields": "dataValidation"
  }
}

References:

  • Related