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

BUG: setValue in formulas automatically sets @ in formula when using ranges #3708

Closed
HAL0594 opened this issue Sep 5, 2023 · 1 comment
Closed

Comments

@HAL0594
Copy link

HAL0594 commented Sep 5, 2023

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?

when defining my form I am doing it in the following way

$formula = '=IF(A' . $row . '<>"",SUM(SUMIFS(\'TABLE1\'!C2:C713,\'TABLE1\'!A2:A713,\'WORKSHEET\'!$H$' . $row . ':$Q$' . $row . ')),"")';
$cell->setValueExplicit($formula, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA);

but when generating the .xlsx document an @ has been automatically added to the range preventing it from being calculated correctly, for example:

=IF(A19<>"",SUM(SUMIFS('TABLE1'!C2:C713,'TABLE1'!A2:A713,@'WORKSHEET'!$H$19:$Q$19)),"")

What is the current behavior?

    for ($row = $range[2]; $row <= $range[3]; $row++) {
        for ($col = $this->getColumnIndex($range[0]); $col <= $this->getColumnIndex($range[1]); $col++) {
            $cell = $sheet->getCellByColumnAndRow($col, $row);
            $formula = '=IF(A' . $row . '<>"",SUM(SUMIFS(\'TABLE1\'!C2:C713,\'TABLE1\'!A2:A713,\'WORKSHEET\'!$H$' . $row . ':$Q$' . $row . ')),"")';
            $cell->setValueExplicit($formula, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA);
        }
    }

Which versions of PhpSpreadsheet and PHP are affected?

v.1.28

@oleibman
Copy link
Collaborator

oleibman commented Sep 5, 2023

See #3659 (comment) for an explanation of the at sign. As I mentioned in that comment, I haven't been able to figure out what has to be done to keep Excel from adding it (it is not present in the spreadsheet generated by PhpSpreadsheet).

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

No branches or pull requests

2 participants