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

Fix for #2224 #2225

Merged
merged 7 commits into from
Jul 21, 2021
Merged

Fix for #2224 #2225

merged 7 commits into from
Jul 21, 2021

Conversation

lucasnetau
Copy link
Contributor

@lucasnetau lucasnetau commented Jul 16, 2021

Fixes #2224 Fix reading data validation flags allowBlank, showDropDown, showInputMessage, showErrorMessage in XLSX reader (was a loose comparison of SimpleXML object to integer), flag values may also be string true/false not just 0/1.

filter_var( $flag, FILTER_VALIDATE_BOOLEAN) chosen to handle both 0/1 and true/false values in the file being read.

This is:

- [X] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

Data validation flags are lost when reading an XLSX file containing true/false boolean values and writing it out after editing.

…utMessage, showErrorMessage in XLSX reader (was a loose comparison of SimpleXML object to integer), flag values may also be string true/false not just 0/1.

  filter_var( $flag, FILTER_VALIDATE_BOOLEAN) chosen to handle both 0/1 and true/false values in the file being read.
* Fix writing data validation flag showDropDown (Inverted logic in reader was replicated to Writer)
@oleibman
Copy link
Collaborator

Are you able to add some unit tests to show that files which do have true/false rather than 1/0 are handled correctly?

@lucasnetau
Copy link
Contributor Author

OK, I shall attempt a unit test for this PR.

The true/false values are in xlsx documents created or edited in LibreOffice. This is valid under the schema definition https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.datavalidation?view=openxml-2.8.1

The possible values for this attribute are defined by the W3C XML Schema boolean datatype.

And based on https://www.w3.org/TR/xmlschema-2/#boolean

An instance of a datatype that is defined as ·boolean· can have the following legal literals {true, false, 1, 0}.

… is apparently incorrect documentation, it works as hideDropDrop if true.
…ion boolean values and those with 1/0 (Excel, GoogleSheets)
@lucasnetau
Copy link
Contributor Author

Unit tests added with both DataValidation defined with true/false and also 1/0

I've reverted the change to showDropDown as upon further investigation this flag is misdefined in the specification and acts as a hideDropDown, which is the reason behind the inversion in both Reader and Writer. I have instead added a brief comment on the relevant lines when it is read and written.

@oleibman oleibman merged commit 11bf051 into PHPOffice:master Jul 21, 2021
@oleibman
Copy link
Collaborator

Thank you for your contribution, and for the excellent documentation of what you've done.

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

Successfully merging this pull request may close these issues.

Data Validation flags not read correctly when reading XLSX files
2 participants