Skip to content

An exception is thrown when trying to read an Excel document without a styles.xml file inside #2246

@arraintxo

Description

@arraintxo

This is:

- [x] a bug report
- [ ] a feature request
- [x] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Document should be readed without any problem, LibreOffice and Microsoft Office do not throw any error on this kind of files.

What is the current behavior?

An exception is thrown when trying to read an Excel document without a styles.xml file inside

TypeError: Argument 1 passed to PhpOffice\PhpSpreadsheet\Reader\Xlsx\Styles::__construct() must be an instance of SimpleXMLElement, bool given, called in /var/www/laravel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php on line 566

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

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

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$filename = './withoutStylesTest.xlsx';
$reader = new Xlsx();
$reader->load($filename);

// add code that show the issue here...
TypeError: Argument 1 passed to PhpOffice\PhpSpreadsheet\Reader\Xlsx\Styles::__construct() must be an instance of SimpleXMLElement, bool given, called in /var/www/laravel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php on line 566

/var/www/laravel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx/Styles.php:31
/var/www/laravel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php:566
/var/www/laravel/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/IOFactory.php:86
/var/www/laravel/app/Services/Import/Mapper/BiddingsXlsMapper.php:13

withoutStylesTest.xlsx

Which versions of PhpSpreadsheet and PHP are affected?

Checked on PHP 8.0 and PhpSpreadsheet 1.18

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