0

When I try to open/read the spreadsheet (xls), I get the following error:

Scale must be greater than or equal to 1

I am using the following code to open and read the file:

$filename = 'test.xls';
$spreadsheet = IOFactory::load($filename); //<-- ERRORS HERE
$worksheet = $spreadsheet->getActiveSheet();

The error occurs on the ::load command.

It isn't a data issue - I can copy the existing data into a new file and it works correctly, so must be an issue with the file itself.

I am using v1.6.0 of PHPSpreadsheet, which is the latest at time of writing.

Thanks in advance!

EDIT:

This question relates to PHPSpreadsheet, not PHPExcel as listed here: PHPExcel Error: Scale must be greater than or equal to 1

Though similar, an XLSX version of my file works as expected, hence the need to create a separate question. PHPExcel is also now marked as officially dead, so seems logical to add this question to the correct library / tag on SO.

I have since found a solution to the problem (added below), which may also work in PHPExcel, but comes with no warranties!

ed13
  • 349
  • 5
  • 19
  • Possible duplicate of [PHPExcel Error: Scale must be greater than or equal to 1](https://stackoverflow.com/questions/25915792/phpexcel-error-scale-must-be-greater-than-or-equal-to-1) – Nico Haase Feb 11 '19 at 10:09
  • @NicoHaase It's a similar issue, but a different library. That relates to PHPExcel - this is PHPSpreadsheet. – ed13 Feb 11 '19 at 10:30
  • 1
    `PHPSpreadsheet` is just a more current version of `PHPExcel` – Nico Haase Feb 11 '19 at 10:31
  • @NicoHaase Perhaps, but the codebase is different - the files referenced in that answer don't exist in PHPSpreadsheet. I am also using XLS - an XLSX version of my file works as expected. – ed13 Feb 11 '19 at 10:58

2 Answers2

0

you can use :

$spreadsheet = \IOFactory::load($filename);
TuChiDo
  • 53
  • 5
0

OK, I have found a solution to my particular problem...

It requires an edit to the setZoomScale function which can be found in SheetView.php.

The zoomscale in my file had a value of zero, which threw an error. The new code checks for this and if found, sets it to 1.

Perhaps not ideal solution for everyone, but works in a pinch:

public function setZoomScale($pValue)
{
    /* NEW code that sets the zoom scale 
    ------------------------------------------*/

    //Zoom Scale of 0 causes error. If found, default pValue to 1.
    if( $pValue == 0)
    {
        $pValue = 1;
    }

    /*----------------------------------------*/

    // Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
    // but it is apparently still able to handle any scale >= 1
    if (($pValue >= 1) || $pValue === null) 
    {
        $this->zoomScale = $pValue;
    } 
    else 
    {
        throw new PhpSpreadsheetException('Scale must be greater than or equal to 1.');
    }

    return $this;
}
ed13
  • 349
  • 5
  • 19
  • If that solved your problem without breaking anything else, could you write a bug report for that library to include your fix? This ensures that you can perform upgrades to later versions – Nico Haase Feb 11 '19 at 11:13