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

.xlsx data validation - PHPSpreadsheet expects operator, but Excel omits it for default "between" #3863

Closed
2 of 8 tasks
jonas-grobe opened this issue Jan 10, 2024 · 0 comments · Fixed by #3865
Closed
2 of 8 tasks

Comments

@jonas-grobe
Copy link

This is a bug report.

If I save a file as .xlsx in Excel (I am using the most recent version, 2312) and I use a "between" data validation, this is how Excel saves the validation:

<dataValidation type="whole" allowBlank="1" showInputMessage="1" showErrorMessage="1" sqref="A1" xr:uid="{465FAF3B-BCA5-447F-AA54-1A5FA9E135C4}">

No operator="between" like Excel would add for other operators and PHPSpreadsheet seems to expect.

What is the expected behavior?

I think if no operator is given, "between" should be assumed.
From the xlsx spec:

<xsd:attribute name="operator" type="x:ST_DataValidationOperator" use="optional" default="between"/>

What is the current behavior?

$dataValidation['operator'] is null and gets parsed into an empty string "".

What are the steps to reproduce?

min_example_validation_between.xlsx

<?php

require __DIR__ . '/vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Cell\DataValidation;

$file = "min_example_validation_between.xlsx";
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file);
$sheet = $spreadsheet->getSheetByName('01');
$validation_type = $sheet->getCell("A1")->getDataValidation()->getOperator();
var_dump(DataValidation::OPERATOR_BETWEEN); // "between"
echo "<br>";
var_dump($validation_type); // "", expected: "between"
echo "<br>";
var_dump($validation_type == DataValidation::OPERATOR_BETWEEN); // false, expected: true

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

.xlsx is affected, didn't try others yet.

Which versions of PhpSpreadsheet and PHP are affected?

I am using PHPSpreadsheet 1.29.0 with PHP 8.0.12

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Jan 12, 2024
Fix PHPOffice#3863. Data Validation default operator is `between`. When Excel writes out a data validation item, it may omit the operator. Xlsx reader will therefore initialize operator to null string. Issue indicates that user wants `between` returned for `getOperator`. A more serious problem is that `isValid` method does not handle this situation correctly. Data Validation is changed to set Operator to the default value if an attempt is made to set it to null string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant