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] Worksheet name in formula fails if title contains parentheses #3201

Closed
2 of 9 tasks
XGhozt opened this issue Nov 23, 2022 · 2 comments
Closed
2 of 9 tasks

[Bug] Worksheet name in formula fails if title contains parentheses #3201

XGhozt opened this issue Nov 23, 2022 · 2 comments

Comments

@XGhozt
Copy link

XGhozt commented Nov 23, 2022

This is:

  • a bug report

What is the expected behavior?

Unchanged cell value.

What is the current behavior?

A working formulae is erroring which results in calculating the formula (correctly) instead of preserving the cell value.

"Syntax error: 'Example (A), lookahead: ', current char: 31"

What are the steps to reproduce?

On a spreadsheet that has tabs, if a formula includes a reference to a tab that has a parentheses in the title, it fails to parse the formula.

For example: =SUM('Example (A)'!$A$2:$A$9999)

Where the name of the other tab is Example (A)

Looks to be a problem with the writeFormula() parser script that just assumes and ( and ) is some kind of formula.

What features do you think are causing the issue

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

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

Have only tested Xls.

Which versions of PhpSpreadsheet and PHP are affected?

Last tested on: v1.25.2

@MarkBaker
Copy link
Member

Unable to replicate:

$spreadsheet = new Spreadsheet();

$worksheet = $spreadsheet->getActiveSheet();
$dataSheet = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, 'Example (A)');
$spreadsheet->addSheet($dataSheet);

$data = [["DATA"], [1], [2], [3]];
$formula = "=SUM('Example (A)'!\$A\$2:\$A\$9999)";

$worksheet->getCell('A1')->setValue($formula);
$dataSheet->fromArray($data, null, 'A1');

var_dump($worksheet->getCell('A1')->getValue(), $worksheet->getCell('A1')->getCalculatedValue());

$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xls($spreadsheet);

$writer->save('BraceInWorksheetName.xls');

@MarkBaker
Copy link
Member

Neither the Writer, nor the Calculation Engine has a problem with worksheet names that contain braces

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