Skip to content

Commit 12ae0d2

Browse files
authored
Merge pull request #2849 from PHPOffice/Issue-2848_Xlsx-Reader-Invalid-Print-Area
Don't load invalid Print Area, because this will corrupt the internal print area definition, and break on Writing
2 parents 7c1c896 + 924ec23 commit 12ae0d2

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
3232

3333
- Xls Reader resolving absolute named ranges to relative ranges [Issue #2826](https://github.com/PHPOffice/PhpSpreadsheet/issues/2826) [PR #2827](https://github.com/PHPOffice/PhpSpreadsheet/pull/2827)
3434
- Null value handling in the Excel Math/Trig PRODUCT() function [Issue #2833](https://github.com/PHPOffice/PhpSpreadsheet/issues/2833) [PR #2834](https://github.com/PHPOffice/PhpSpreadsheet/pull/2834)
35-
35+
- Invalid Print Area defined in Xlsx corrupts internal storage of print area [Issue #2848](https://github.com/PHPOffice/PhpSpreadsheet/issues/2848) [PR #2849](https://github.com/PHPOffice/PhpSpreadsheet/pull/2849)
3636

3737
## 1.23.0 - 2022-04-24
3838

src/PhpSpreadsheet/Reader/Xlsx.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,13 +1530,18 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
15301530
$rangeSets = preg_split("/('?(?:.*?)'?(?:![A-Z0-9]+:[A-Z0-9]+)),?/", $extractedRange, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
15311531
$newRangeSets = [];
15321532
foreach ($rangeSets as $rangeSet) {
1533-
[$sheetName, $rangeSet] = Worksheet::extractSheetTitle($rangeSet, true);
1533+
[, $rangeSet] = Worksheet::extractSheetTitle($rangeSet, true);
1534+
if (empty($rangeSet)) {
1535+
continue;
1536+
}
15341537
if (strpos($rangeSet, ':') === false) {
15351538
$rangeSet = $rangeSet . ':' . $rangeSet;
15361539
}
15371540
$newRangeSets[] = str_replace('$', '', $rangeSet);
15381541
}
1539-
$docSheet->getPageSetup()->setPrintArea(implode(',', $newRangeSets));
1542+
if (count($newRangeSets) > 0) {
1543+
$docSheet->getPageSetup()->setPrintArea(implode(',', $newRangeSets));
1544+
}
15401545

15411546
break;
15421547
default:

0 commit comments

Comments
 (0)