问题
Im trying to generate an Google Spreadsheet Template with some Validation with their API, using the Node.Js Package from Google.
This is my current Request:
{
"setDataValidation": {
"range": {
"sheetId": 1656514345,
"startRowIndex": 0,
"endRowIndex": 0,
"startColumnIndex": 1,
"endColumnIndex": 1000
},
"rule": {
"condition": {
"type": "CUSTOM_FORMULA",
"values": [
{
"userEnteredValue": "=REGEXMATCH(TO_TEXT(A2:A1000); '([1-9]){4}[-]([1-9]){2}[-]([1-9]){2}$')"
}
]
},
"inputMessage": "TEST VALIDATION",
"strict": true
}
}
}
I get the following Error:
Error: Invalid requests[0].setDataValidation: Invalid ConditionValue.userEnteredValue: =REGEXMATCH(TO_TEXT(A2:A1000); '([1-9]){4}[-]([1-9]){2}[-]([1-9]){2}$')
A simple create or append Data in the Spreadsheet works fine, but getting an Regex Validation to work seems like the limit. In the Documentation there seems no limitation for RegEx, what is wrong with my Request?
Thanks in Advance.
回答1:
Your expression needs to be escaped.
"userEnteredValue": "=REGEXMATCH(TO_TEXT(A1), \"[0-9]{4}[-][0-9]{2}[-][0-9]{2}$\")"
Note that the internal quotes are escaped (\"
instead of "
).
Note that single quotes also won't work.
来源:https://stackoverflow.com/questions/58977942/google-spreadsheet-api-setdatavalidation-with-regex