本文介绍了带有正则表达式的Google Spreadsheet API setDataValidation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Google的Node.Js包生成带有其API验证的Google Spreadsheet模板.
Im trying to generate an Google Spreadsheet Template with some Validation with their API, using the Node.Js Package from Google.
这是我当前的请求:
{
"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
}
}
}
我收到以下错误消息:
Error: Invalid requests[0].setDataValidation: Invalid ConditionValue.userEnteredValue: =REGEXMATCH(TO_TEXT(A2:A1000); '([1-9]){4}[-]([1-9]){2}[-]([1-9]){2}$')
在电子表格中简单地创建或追加数据可以很好地工作,但是使Regex验证正常工作似乎是极限.在文档中,似乎没有限制RegEx,我的请求出了什么问题?
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?
预先感谢.
推荐答案
您的表达式需要转义.
"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.
这篇关于带有正则表达式的Google Spreadsheet API setDataValidation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!