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

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

Closed
arraintxo opened this issue Aug 2, 2021 · 1 comment

Comments

@arraintxo
Copy link
Contributor

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

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Aug 13, 2021
This is an exact replacement for PR PHPOffice#2247 by @arraintxo. That PR has reached a state in Github where it cannot be merged, and I am not sure how to fix it, other than by re-submitting it as this PR.

See issue PHPOffice#2246. A spreadsheet lacking styles.xml is throwing an exception on Read. Additionally, after fixing that problem, attempting to save the object that has been read throws an exception. This is also true for a spreadsheet with an empty styles.xml.
@PowerKiKi
Copy link
Member

Fixed in 1.19.0

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