Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataValidation without additional sheet #16

Closed
SHAESEN2 opened this issue Nov 25, 2019 · 4 comments
Closed

DataValidation without additional sheet #16

SHAESEN2 opened this issue Nov 25, 2019 · 4 comments

Comments

@SHAESEN2
Copy link
Contributor

I would be very helpful to add validation to a column of a sheet, without referring to string values in another sheet. The code could look like:

dataValidation(wb, 1, col = 1, rows = 2:3, type = "list", value = c("", val1", "val2"))
@ycphs
Copy link
Owner

ycphs commented Nov 25, 2019

Please provide an xlsx file, which has this behaviour.

If you do it manually in Excel for type "list", you have to choose a range of to have the allowed values.

@SHAESEN2
Copy link
Contributor Author

It can not be done in excel via 'data validation'. I was hoping it could be forced in via R code.

@ycphs
Copy link
Owner

ycphs commented Nov 25, 2019

If it can't be done in Excel, then it is not possible to create a valid xlsx-file.

@ycphs ycphs closed this as completed Nov 25, 2019
@tentacles-from-outer-space
Copy link
Contributor

This can definitely be done in Ecel, and in fact also in openxlsx using the following code:

dataValidation(wb, 1, col = 1, rows = 2:3, type = "list", value = "\",val1,val2\""))
# or
dataValidation(wb, 1, col = 1, rows = 2:3, type = "list", value = '",val1,val2"'))

Double quotes are essential for this to work.

So if one had vector of values:

v <- c("a", "b", "c")
dataValidation(......., value = paste0('"', paste0(v, collapse=","), '"'))

This could be added as an example on dataValidation help page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants