From bdc95b14bf51015a3b82d73dd0d5934359b85484 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 26 Feb 2018 14:30:44 -0600 Subject: [PATCH] Select correct cell when calling freezePane Fixes a bug when calling `$sheet->freezePane('B2')` without a second argument. The selected cell will now be `B2` instead of the incorrect `B3`. Fixes #389 Closes #393 --- CHANGELOG.md | 1 + src/PhpSpreadsheet/Worksheet/Worksheet.php | 4 ++-- tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2622163..19eddc84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Use proper € symbol for currency format - [#379](https://github.com/PHPOffice/PhpSpreadsheet/pull/379) - Read printing area correctly when skipping some sheets - [#371](https://github.com/PHPOffice/PhpSpreadsheet/issues/371) - Avoid incorrectly overwriting calculated value type - [#394](https://github.com/PHPOffice/PhpSpreadsheet/issues/394) +- Select correct cell when calling freezePane - [#389](https://github.com/PHPOffice/PhpSpreadsheet/issues/389) ## [1.1.0] - 2018-01-28 diff --git a/src/PhpSpreadsheet/Worksheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet/Worksheet.php index c7f08fee..156a360c 100644 --- a/src/PhpSpreadsheet/Worksheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet/Worksheet.php @@ -1971,7 +1971,7 @@ class Worksheet implements IComparable * * - A2 will freeze the rows above cell A2 (i.e row 1) * - B1 will freeze the columns to the left of cell B1 (i.e column A) - * - B2 will freeze the rows above and to the left of cell A2 (i.e row 1 and column A) + * - B2 will freeze the rows above and to the left of cell B2 (i.e row 1 and column A) * * @param null|string $cell Position of the split * @param null|string $topLeftCell default position of the right bottom pane @@ -1988,7 +1988,7 @@ class Worksheet implements IComparable if ($cell !== null && $topLeftCell === null) { $coordinate = Coordinate::coordinateFromString($cell); - $topLeftCell = $coordinate[0] . ($coordinate[1] + 1); + $topLeftCell = $coordinate[0] . $coordinate[1]; } $this->freezePane = $cell; diff --git a/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php b/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php index d92a3d08..5dfa8259 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php @@ -123,4 +123,11 @@ class WorksheetTest extends TestCase $sheet->setCodeName('Test Code Name', false); self::assertSame('Test Code Name', $sheet->getCodeName()); } + + public function testFreezePaneSelectedCell() + { + $worksheet = new Worksheet(); + $worksheet->freezePane('B2'); + self::assertSame('B2', $worksheet->getTopLeftCell()); + } }