Skip to content

INDIRECT function not working with Defined names in excel #1993

Closed
@Lzolcsi

Description

@Lzolcsi

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)

I have an excel file that uses defined names and I use the INDIRECT function to reference them, but this throws an error when trying to access the calculated value of the cell.

What is the expected behavior?

-return the correct value (300 in this case)

What is the current behavior?

PhpSpreadsheet throws the following Exceptions:

PHP Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Calculation\Exception: Worksheet!B3 -> Invalid cell coordinate =B1 in /Users/zolcsi/www/szamlazo/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php:272
Stack trace:
#0 /Users/zolcsi/www/szamlazo/bin/inc/modules/Project.php(5014): PhpOffice\PhpSpreadsheet\Cell\Cell->getCalculatedValue()
#1 /Users/zolcsi/www/szamlazo/bin/inc/modules/Project.php(155): Project->XlsGyartoSzallitoMegfeleltetes()
#2 /Users/zolcsi/www/szamlazo/bin/inc/common.php(48): Project->Execute()
#3 /Users/zolcsi/www/szamlazo/html/index.php(19): require_once('/Users/zolcsi/w...')
#4 {main}
thrown in /Users/zolcsi/www/szamlazo/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php on line 272

Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Calculation\Exception: Worksheet!B3 -> Invalid cell coordinate =B1 in /Users/zolcsi/www/szamlazo/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php:272
Stack trace:
#0 /Users/zolcsi/www/szamlazo/bin/inc/modules/Project.php(5014): PhpOffice\PhpSpreadsheet\Cell\Cell->getCalculatedValue()
#1 /Users/zolcsi/www/szamlazo/bin/inc/modules/Project.php(155): Project->XlsGyartoSzallitoMegfeleltetes()
#2 /Users/zolcsi/www/szamlazo/bin/inc/common.php(48): Project->Execute()
#3 /Users/zolcsi/www/szamlazo/html/index.php(19): require_once('/Users/zolcsi/w...')
#4 {main}
thrown in /Users/zolcsi/www/szamlazo/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php on line 272

What are the steps to reproduce?

<?php

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


$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'EUR');
$sheet->setCellValue('A2', 'USD');
$sheet->setCellValue('A3', 'EUR');
$sheet->setCellValue('B1', 360);
$sheet->setCellValue('B2', 300);

$spreadsheet->addNamedRange( new \PhpOffice\PhpSpreadsheet\NamedRange('EUR', $sheet, '=$B$1') );
$spreadsheet->addNamedRange( new \PhpOffice\PhpSpreadsheet\NamedRange('USD', $sheet, '=$B$2') );
$sheet->setCellValue('B3', '=INDIRECT("USD")');
var_dump($sheet -> getCell('B3') -> getCalculatedValue());


### Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet 1.17.1
PHP 7.4.16

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions