PhpSpreadsheet: xls file cause the exception during open by Xls reader

This is:

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

What is the expected behavior?

Excel file opened for reading/write I tried to use deprecated PhpExcel classes and the file opens successfully!

What is the current behavior?

Trying to open test excel file cause the exception:

Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Reader\Exception: Parameter data is empty. in /home/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/OLERead.php:331 Stack trace: #0 /home/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/OLERead.php(281): PhpOffice\PhpSpreadsheet\Shared\OLERead::getInt4d('\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00...', 116) #1 /home/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/OLERead.php(187): PhpOffice\PhpSpreadsheet\Shared\OLERead->readPropertySets() #2 /home/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xls.php(1363): PhpOffice\PhpSpreadsheet\Shared\OLERead->read('/tmp/phpk3bjPS') #3 /home/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xls.php(628): PhpOffice\PhpSpreadsheet\Reader\ in /home/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/OLERead.php on line 331

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
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
  $spreadsheet = $reader->load($_FILES['EXP_FILE']['tmp_name']);
  var_dump($spreadsheet->getSheet(0)->getCell('A1')->getValue());die;

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet 1.1 php 7.1

test.zip

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 27 (6 by maintainers)

Commits related to this issue

Most upvoted comments

This file was generated 3rd party software (Scanlister). I understand this file may have mistakes in structure, but LibreOffice, OpenOffice, MS Office opened this files without any errors. I think such files should be supported by PhpSpreadsheet also.

@GianinaSalomo thanks for reporting back. Maybe you could create a separate issue, linking to this one, with more details about the warnings ?

I have the same bug. Here, a fix, that help me:

use PhpOffice\PhpSpreadsheet\Reader\Xls as ExcelReader;
$oldEncoding = "";
$filepath = "test.xls";
if (function_exists("mb_internal_encoding"))
{
	$oldEncoding = mb_internal_encoding();
	mb_internal_encoding('latin1');
	$reader = new PhpOffice\PhpSpreadsheet\Reader\Xls;
	$spreadsheet = $reader->load($filepath);
	mb_internal_encoding($oldEncoding);
}

// Example action
$maxRow = $spreadsheet->getActiveSheet()->getHighestRow();
print_r($maxRow);