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

Add support for Worksheet DataValidations #38

Merged
merged 5 commits into from
Sep 13, 2018

Conversation

rodney757
Copy link
Contributor

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.

@ochedru
Copy link
Collaborator

ochedru commented Sep 12, 2018

Thank you for your PR. Did you forget to include some files in your commit?

@rodney757
Copy link
Contributor Author

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())
Copy link
Collaborator

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) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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);
}
Copy link
Collaborator

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) {
Copy link
Collaborator

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.

@ochedru
Copy link
Collaborator

ochedru commented Sep 13, 2018

Nice job. Thank you!

@ochedru ochedru merged commit 6889cae into dhatim:master Sep 13, 2018
@ochedru ochedru mentioned this pull request Sep 13, 2018
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

Successfully merging this pull request may close these issues.

None yet

3 participants