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

ANCHORARRAY() doen't work in validation #4197

Closed
6 tasks
j4vs opened this issue Oct 22, 2024 · 2 comments · Fixed by #4203
Closed
6 tasks

ANCHORARRAY() doen't work in validation #4197

j4vs opened this issue Oct 22, 2024 · 2 comments · Fixed by #4203

Comments

@j4vs
Copy link

j4vs commented Oct 22, 2024

This is:

- [ x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

The correct rendered of ANCHORARRAY() in validatios

What is the current behavior?

When use ANCHORARRAY() in validations, doesn't rendered

$validation->setFormula1('=ANCHORARRAY($B$1)');

imagen

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

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

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

$sheet = $spreadsheet->getActiveSheet();

$validation = $sheet->getCell("A1")->getDataValidation();

$validation->setType(DataValidation::TYPE_LIST);
$validation->setErrorStyle(DataValidation::STYLE_STOP);
$validation->setAllowBlank(true);
$validation->setShowDropDown(true);
$validation->setFormula1('=ANCHORARRAY($B$1)');

$sheet->getCell("A1")->setDataValidation($validation);

If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.

What features do you think are causing the issue

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

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

Which versions of PhpSpreadsheet and PHP are affected?

@oleibman
Copy link
Collaborator

Confirmed. PhpSpreadsheet is not adding the prefix which Excel requires for functions introduced after Excel 2007 (like ANCHORARRAY) to formulas used in Data Validation. While I work out what needs to be done to PhpSpreadsheet, you may be able to work around the problem using the following statement:

$validation->setFormula1('_xlfn.ANCHORARRAY($B$1)');

That should be good enough for write. I am unsure whether it will be read correctly when you load a spreadsheet.

@oleibman
Copy link
Collaborator

It looks relatively straightforward to handle the formula on read and write. What is not straightforward is getting the DataValidator::isValid method working with a list specified in this manner. How important is that to you?

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Oct 27, 2024
Fix PHPOffice#4197. Overlooked in the introduction of Dynamic Arrays, Data Validation can specify a list to be a result of the spill operator, which is implemented via the ANCHORARRAY function.

It appears that function `DataValidator::isValid` will not work if the list is specified in this manner, nor if it is specified as a defined name. Fixing those situations will be difficult (defined names probably easier than ANCHORARRAY), and there is no reason to delay this change waiting for those to be fixed. I will open a new issue when this PR is merged.
@PHPOffice PHPOffice deleted a comment Oct 28, 2024
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.

3 participants
@oleibman @j4vs and others