Skip to content

Commit bdc95b1

Browse files
UziTechPowerKiKi
authored andcommitted
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
1 parent a089a87 commit bdc95b1

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2020
- Use proper € symbol for currency format - [#379](https://github.com/PHPOffice/PhpSpreadsheet/pull/379)
2121
- Read printing area correctly when skipping some sheets - [#371](https://github.com/PHPOffice/PhpSpreadsheet/issues/371)
2222
- Avoid incorrectly overwriting calculated value type - [#394](https://github.com/PHPOffice/PhpSpreadsheet/issues/394)
23+
- Select correct cell when calling freezePane - [#389](https://github.com/PHPOffice/PhpSpreadsheet/issues/389)
2324

2425
## [1.1.0] - 2018-01-28
2526

src/PhpSpreadsheet/Worksheet/Worksheet.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,7 @@ public function getFreezePane()
19711971
*
19721972
* - A2 will freeze the rows above cell A2 (i.e row 1)
19731973
* - B1 will freeze the columns to the left of cell B1 (i.e column A)
1974-
* - B2 will freeze the rows above and to the left of cell A2 (i.e row 1 and column A)
1974+
* - B2 will freeze the rows above and to the left of cell B2 (i.e row 1 and column A)
19751975
*
19761976
* @param null|string $cell Position of the split
19771977
* @param null|string $topLeftCell default position of the right bottom pane
@@ -1988,7 +1988,7 @@ public function freezePane($cell, $topLeftCell = null)
19881988

19891989
if ($cell !== null && $topLeftCell === null) {
19901990
$coordinate = Coordinate::coordinateFromString($cell);
1991-
$topLeftCell = $coordinate[0] . ($coordinate[1] + 1);
1991+
$topLeftCell = $coordinate[0] . $coordinate[1];
19921992
}
19931993

19941994
$this->freezePane = $cell;

tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,11 @@ public function testSetCodeNameDuplicate()
123123
$sheet->setCodeName('Test Code Name', false);
124124
self::assertSame('Test Code Name', $sheet->getCodeName());
125125
}
126+
127+
public function testFreezePaneSelectedCell()
128+
{
129+
$worksheet = new Worksheet();
130+
$worksheet->freezePane('B2');
131+
self::assertSame('B2', $worksheet->getTopLeftCell());
132+
}
126133
}

0 commit comments

Comments
 (0)