Skip to content

After patching PHPSpreadsheet 4.0.0 with PR #4360, in a sheet with a title containing an apostrophe, applying a style format to a named cell crashes the application. #4362

@Awilen-Bernkastel

Description

@Awilen-Bernkastel

This is:

What is the expected behavior?

Follow-up issue to issue #4356, PR #4360 is applied.

The application of a number format to a cell in a sheet containing an apostrophe should apply the format properly.

What is the current behavior?

The application crashes with exception 'Invalid Worksheet for specified Range' (Style/Style.php line 194).

What are the steps to reproduce?

$filePath='Problematic sheet name.xlsx';

$reader = IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load($filePath);

$cellName = 'CELLNAME';

$namedRange = $spreadsheet->getNamedRange($cellName);
if (!is_null($namedRange)) {
    $namedRange->getWorksheet()->getCell($namedRange->getCellsInRange()[0])->setValue(\PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(new DateTime(date('Y-m-d'))));
    $sheet = $namedRange->getWorksheet();
    $style = $sheet->getStyle($cellName);
    $numberFormat = $style->getNumberFormat();

    $numberFormat->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DDMMYYYY);
}

Observe the crash.

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

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: 4.0.0
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