-
Notifications
You must be signed in to change notification settings - Fork 121
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
Add support for Worksheet DataValidations #38
Conversation
Thank you for your PR. Did you forget to include some files in your commit? |
75ce6c0
to
73fa7fc
Compare
oops, I sure did. Added them now. |
.append("\" showDropDown=\"") | ||
.append(String.valueOf(!showDropdown)) // for some reason, this is the inverse of what you'd expect | ||
.append("\" errorStyle=\"") | ||
.append(errorStyle.toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errorStyle
can be null
: it should be initialized with a default value.
* @param range The Range this validation is applied to | ||
* @param listRange The Range of the list this validation references | ||
*/ | ||
static ListDataValidation list(Range range, Range listRange) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be nicer to build a validation from the range we want to validate. So we could get rid of this factory and we would not need to expose DataValidation
interface and implementations.
This could result in the more expressive example:
ws.range(<to validate>).validateWithList(ws.range(<coordinates of list>));
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, I'll make the changes
*/ | ||
public ListDataValidation validateWithList(Range listRange) { | ||
return new ListDataValidation(this, listRange); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The returned ListDataValidation
should be added to the worksheet.
@@ -143,6 +147,10 @@ void shadeAlternateRows(Range range, Fill fill) { | |||
alternateShadingRanges.add(new AlternateShading(range, getWorkbook().cacheAlternateShadingFillColor(fill))); | |||
} | |||
|
|||
public void addValidation(DataValidation validation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be public but package private.
Nice job. Thank you! |
This PR provides a way to implement [DataValidation](https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2010/cc881341(v%3doffice.14) for aWorksheet.
This adds a ListDataValidation for validating cells against a list. Other DataValidations can easily be implemented as necessary.