Skip to content

Incorrect formula parsing #2874

Closed
Closed
@Zhonkey

Description

This is:

- [*] 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)

Formulas for check:
='Sheet1'!$A3 + MIN('Sheet1'!A:A)

What is the expected behavior?

'Sheet1'!$A3 + MIN('Sheet1'!A:A) - should be parsed as 'Some page'!$A3 plus MIN('Sheet1'!A:A)

What is the current behavior?

'Sheet1'!$A3 + MIN('Sheet1'!A:A) - parsed as cell with address A:A on sheet "'Some page'!$A3 + MIN('Sheet1'"

What are the steps to reproduce?

<?php

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

// Create new Spreadsheet object
        $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
        $sheet1 = new Worksheet($spreadsheet, 'sheet1');
        $spreadsheet->addSheet($sheet1, 1);
        $sheet1->setCellValue('A1', 1);
        $sheet1->setCellValue('A2', 1);

        $sheet2 = new Worksheet($spreadsheet, 'sheet2');
        $spreadsheet->addSheet($sheet2, 2);
        $sheet2->setCellValue('A1', '=MIN(\'sheet1\'!A:A) + \'sheet1\'!A1');
//        If you change two terms, it parsed correctly
//        $sheet2->setCellValue('A1', '=\'sheet1\'!A1 + MIN(\'sheet1\'!A:A)');

        var_dump($sheet2->getCell('A1')->getCalculatedValue());

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • [* ] Formula Calulations
  • 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?

Main problem is in regexp patterns from PhpOffice\PhpSpreadsheet\Calculation\Calculation.
As i understand, need to replace all '.?' to '([^']|'')?'

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions