Skip to content

Commit

Permalink
Fix print area parser for XLSX reader
Browse files Browse the repository at this point in the history
XLSX workbook references may not contains quotes in print area

Fixes PHPOffice#733
Fixes PHPOffice#734
  • Loading branch information
guillaume-ro-fr committed Jun 12, 2019
1 parent a517f7b commit c98dc07
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,7 @@ public function load($pFilename)

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);
Expand Down
7 changes: 6 additions & 1 deletion tests/PhpSpreadsheetTests/Functional/PrintAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ public function testPageSetup($format)
$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');
}
}

0 comments on commit c98dc07

Please sign in to comment.