diff --git a/CHANGELOG.md b/CHANGELOG.md index c3f6cb5f..1c3ef129 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Support numeric condition in SUMIF, SUMIFS, AVERAGEIF, COUNTIF, MAXIF and MINIF - [#683](https://github.com/PHPOffice/PhpSpreadsheet/issues/683) - SUMIFS containing multiple conditions - [#704](https://github.com/PHPOffice/PhpSpreadsheet/issues/704) - Csv reader avoid notice when the file is empty - [#743](https://github.com/PHPOffice/PhpSpreadsheet/pull/743) +- Fix print area parser for XLSX reader - [#734](https://github.com/PHPOffice/PhpSpreadsheet/pull/734) ## [1.5.0] - 2018-10-21 diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index dfb4b825..fa242a06 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -1830,7 +1830,7 @@ class Xlsx extends BaseReader break; case '_xlnm.Print_Area': - $rangeSets = preg_split("/'(.*?)'(?:![A-Z0-9]+:[A-Z0-9]+,?)/", $extractedRange, PREG_SPLIT_NO_EMPTY); + $rangeSets = preg_split("/('?(?:.*?)'?(?:![A-Z0-9]+:[A-Z0-9]+)),?/", $extractedRange, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $newRangeSets = []; foreach ($rangeSets as $rangeSet) { list($sheetName, $rangeSet) = Worksheet::extractSheetTitle($rangeSet, true); diff --git a/tests/PhpSpreadsheetTests/Functional/PrintAreaTest.php b/tests/PhpSpreadsheetTests/Functional/PrintAreaTest.php index 1a6709c7..7c3a9112 100644 --- a/tests/PhpSpreadsheetTests/Functional/PrintAreaTest.php +++ b/tests/PhpSpreadsheetTests/Functional/PrintAreaTest.php @@ -32,13 +32,18 @@ class PrintAreaTest extends AbstractFunctional $sheet->getPageSetup()->setPrintArea("A$i:B$i"); } + $worksheet4 = $spreadsheet->createSheet()->setTitle('Sheet 4'); + $worksheet4->getPageSetup()->setPrintArea('A4:B4,D1:E4'); + $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format, function (BaseReader $reader) { - $reader->setLoadSheetsOnly(['Sheet 1', 'Sheet 3']); + $reader->setLoadSheetsOnly(['Sheet 1', 'Sheet 3', 'Sheet 4']); }); $actual1 = $reloadedSpreadsheet->getSheetByName('Sheet 1')->getPageSetup()->getPrintArea(); $actual3 = $reloadedSpreadsheet->getSheetByName('Sheet 3')->getPageSetup()->getPrintArea(); + $actual4 = $reloadedSpreadsheet->getSheetByName('Sheet 4')->getPageSetup()->getPrintArea(); self::assertSame('A1:B1', $actual1, 'should be able to write and read normal page setup'); self::assertSame('A3:B3', $actual3, 'should be able to write and read page setup even when skipping sheets'); + self::assertSame('A4:B4,D1:E4', $actual4, 'should be able to write and read page setup with multiple print areas'); } }