Skip to content

Global cell names are not handled properly when the title of the sheet contains an apostrophe / single quote. #4356

Closed
@Awilen-Bernkastel

Description

@Awilen-Bernkastel

This is:

What is the expected behavior?

The global named cells reference the cells in the sheet containing a quote in its title when opened.

What is the current behavior?

The names of the named cells do not reference the cells they were referencing.

What are the steps to reproduce?

Open an Xlsx file containing a named cell in a sheet with a title containing an apostrophe, and call Spreadsheet::getNamedRange("CELLNAME");

$reader = IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load($filePath);
$cellrange = $spreadsheet->getNamedRange("CELLNAME");
var_dump($cellrange);

Observe the empty result.

Here is an Excel file to reproduce this behavior with: Problematic sheet name.xlsx

What features do you think are causing the issue

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

The problematic behavior is located in the method Xlsx::loadSpreadsheetFromFile in the file Reader/Xlsx.php. Adding the following code at line 1825 crudely fixes the problem:

$extractedSheetName = str_replace("''", "'", $extractedSheetName);

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

Not to my knowledge. The affected file format is Xlsx.

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet: 3.9.1
PHP: 8.1

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