Description
This is:
- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question
I'm working with a file generated by another software that I need to fill: read the file, fill some cells and save it again. I use a reader to get the Spreadsheet
instance (so I can set the desired cell values) and a writer to save it.
What is the expected behavior?
Excel file loaded without issues
What is the current behavior?
PHP runs ou of memory
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';
$path = "C:\\path\\to\\file.xls"; // use the attached XLS
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile($path);
$worksheet = $reader->load($path);
// before dump, will run out of memory
die(var_dump($worksheet->getActiveSheet()->toArray()));
After digging into the reader code I found that the range cell is huge (function shrinkRangeToFit
returns E9:GU5420) so the reader thinks the file big (hundred/thousands of empty cells) but the error can be avoided if:
$reader->setReadDataOnly(true)
is used (need the formatting, so no valid for me)strlen($this->data)
is replaced withmb_strlen($this->data)
onsrc/PhpSpreadsheet/Reader/Xls.php
(don't understand why)
I tried this, without success:
- Created a filter as described here
(seems to be ignored) $reader->setReadEmptyCells(false)
(no effect)- Converted to XLSX (exactly the same error)
- Increased memory limit to 1024M (runs out of memory again)
I even but the
What features do you think are causing the issue
- Reader
- Writer
- Styles
- Data Validations
- Formula Calulations
- Charts
- AutoFilter
- Form Elements
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
Tested with XLS and XLSX (attached file)
Which versions of PhpSpreadsheet and PHP are affected?
As far as I know, all of v1 versions (tried with 1.21, 1.22 and 1.23). I tried both on Windows 10 and Ubuntu 20.04 LTS using PHP 8.1.