Skip to content

Commit

Permalink
Fix zoom scale problems on reading bad xlsx files
Browse files Browse the repository at this point in the history
Some computer programs will output xlsx files that do not compare 100%
to the standards. Excel will open the file without any problem.

setZoomScaleNormal() should throw exception when manually setting the
scale to less than or equals 0, but when reading files, we should
be able to read a file with such error, as Excel does.

Closes #350
jasverix authored and PowerKiKi committed Feb 11, 2018
1 parent 608a2ed commit 2e37578
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- HTML writer creates a generator meta tag - [#312](https://github.com/PHPOffice/PhpSpreadsheet/issues/312)
- Support invalid zoom value in XLSX format - [#350](https://github.com/PHPOffice/PhpSpreadsheet/pull/350)

### Fixed

18 changes: 16 additions & 2 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
@@ -702,10 +702,24 @@ public function load($pFilename)

if (isset($xmlSheet->sheetViews, $xmlSheet->sheetViews->sheetView)) {
if (isset($xmlSheet->sheetViews->sheetView['zoomScale'])) {
$docSheet->getSheetView()->setZoomScale((int) ($xmlSheet->sheetViews->sheetView['zoomScale']));
$zoomScale = (int) ($xmlSheet->sheetViews->sheetView['zoomScale']);
if ($zoomScale <= 0) {
// setZoomScale will throw an Exception if the scale is less than or equals 0
// that is OK when manually creating documents, but we should be able to read all documents
$zoomScale = 100;
}

$docSheet->getSheetView()->setZoomScale($zoomScale);
}
if (isset($xmlSheet->sheetViews->sheetView['zoomScaleNormal'])) {
$docSheet->getSheetView()->setZoomScaleNormal((int) ($xmlSheet->sheetViews->sheetView['zoomScaleNormal']));
$zoomScaleNormal = (int) ($xmlSheet->sheetViews->sheetView['zoomScaleNormal']);
if ($zoomScaleNormal <= 0) {
// setZoomScaleNormal will throw an Exception if the scale is less than or equals 0
// that is OK when manually creating documents, but we should be able to read all documents
$zoomScaleNormal = 100;
}

$docSheet->getSheetView()->setZoomScaleNormal($zoomScaleNormal);
}
if (isset($xmlSheet->sheetViews->sheetView['view'])) {
$docSheet->getSheetView()->setView((string) $xmlSheet->sheetViews->sheetView['view']);

0 comments on commit 2e37578

Please sign in to comment.