PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.35k stars 3.47k forks source link

Data Validation #4091

Open bokrma opened 4 months ago

bokrma commented 4 months ago

Currently in the functionality there is only way to set validation per cell public function setDataValidation(string $cellCoordinate, ?DataValidation $dataValidation = null): static and the get also return the range as parts: $this->worksheet->getDataValidationCollection();

can we let it return as defined in the excel file: and also set as range instead of cell by cell Screenshot 2024-07-08 at 16 12 21

oleibman commented 4 months ago

It would be helpful to know what you have in mind. Changing the way the Data Validations are stored would be quite difficult. But I'm guessing that you want to emulate Excel's Data Validation "Apply these changes to all other cells with the same settings". If that is the case, a less difficult solution presents itself. You would need two new methods - one which returns a list of all cells with the same Data Validation as a given cell, and another which copies a Data Validation to a list of cells. Then you could do something like:

$cellList = $sheet->getIdenticalDataValidationList($targetCell);
// apply changes to $targetCell->dataValidation
$sheet->copyDataValidation($targetCell, $cellList);

Would that satisfy your requirement?

bokrma commented 4 months ago

I will try it out, thank you!

oleibman commented 1 day ago

Solving this may have a lot in common with a solution, if any, for #797. I'm going to think about it for a while.