Skip to content

Commit

Permalink
fix active cell with freezing row/col
Browse files Browse the repository at this point in the history
  • Loading branch information
aVadim483 committed Sep 28, 2023
1 parent 22c7165 commit 0b991ed
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/FastExcelWriter/Sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class Sheet
];

protected ?string $activeCell = null;
protected ?string $activeRef = null;

protected array $sheetViews = [];


Expand Down Expand Up @@ -516,10 +518,11 @@ public function setActiveCell($cellAddress): Sheet
ExceptionAddress::throwNew('Wrong cell address %s', print_r($address, 1));
}
if ($address['cell1'] === $address['cell2']) {
$this->activeCell = $address['cell1'];
$this->activeRef = $this->activeCell = $address['cell1'];
}
else {
$this->activeCell = $address['cell1'] . ':' . $address['cell2'];
$this->activeCell = $address['cell1'];
$this->activeRef = $address['cell1'] . ':' . $address['cell2'];
}

return $this;
Expand Down Expand Up @@ -3438,58 +3441,65 @@ public function getSheetViews(): array
}
if ($this->freezeRows && $this->freezeColumns) {
// frozen rows and cols
$activeCell = $this->activeCell ?? Excel::cellAddress($paneRow, $paneCol);
$activeRef = $this->activeRef ?? $activeCell;
$result[$n]['_items'] = [
[
'_tag' => 'pane',
'_attr' => ['ySplit' => $this->freezeRows, 'xSplit' => $this->freezeColumns, 'topLeftCell' => Excel::cellAddress($paneRow, $paneCol), 'activePane' => 'bottomRight', 'state' => 'frozen'],
],
[
'_tag' => 'selection',
'_attr' => ['activeCell' => Excel::cellAddress($paneRow, 1), 'pane' => 'topRight', 'sqref' => Excel::cellAddress($paneRow, 1)],
'_attr' => ['pane' => 'topRight', 'activeCell' => Excel::cellAddress($paneRow, 1), 'sqref' => Excel::cellAddress($paneRow, 1)],
],
[
'_tag' => 'selection',
'_attr' => ['activeCell' => Excel::cellAddress(1, $paneCol), 'pane' => 'bottomLeft', 'sqref' => Excel::cellAddress(1, $paneCol)],
'_attr' => ['pane' => 'bottomLeft', 'activeCell' => Excel::cellAddress(1, $paneCol), 'sqref' => Excel::cellAddress(1, $paneCol)],
],
[
'_tag' => 'selection',
'_attr' => ['activeCell' => Excel::cellAddress($paneRow, $paneCol), 'pane' => 'bottomRight', 'sqref' => Excel::cellAddress($paneRow, $paneCol)],
'_attr' => ['pane' => 'bottomRight', 'activeCell' => $activeCell, 'sqref' => $activeRef],
],
];
}
elseif ($this->freezeRows) {
// frozen rows only
$activeCell = $this->activeCell ?? Excel::cellAddress($paneRow, 1);
$activeRef = $this->activeRef ?? $activeCell;
$result[$n]['_items'] = [
[
'_tag' => 'pane',
'_attr' => ['ySplit' => $this->freezeRows, 'topLeftCell' => Excel::cellAddress($paneRow, 1), 'activePane' => 'bottomRight', 'state' => 'frozen'],
],
[
'_tag' => 'selection',
'_attr' => ['activeCell' => Excel::cellAddress($paneRow, 1), 'pane' => 'bottomLeft', 'sqref' => Excel::cellAddress($paneRow, 1)],
'_attr' => ['pane' => 'bottomLeft', 'activeCell' => $activeCell, 'sqref' => $activeRef],
],
];
}
elseif ($this->freezeColumns) {
// frozen cols only
$activeCell = $this->activeCell ?? Excel::cellAddress(1, $paneCol);
$activeRef = $this->activeRef ?? $activeCell;
$result[$n]['_items'] = [
[
'_tag' => 'pane',
'_attr' => ['xSplit' => $this->freezeColumns, 'topLeftCell' => Excel::cellAddress(1, $paneCol), 'activePane' => 'topRight', 'state' => 'frozen'],
],
[
'_tag' => 'selection',
'_attr' => ['activeCell' => Excel::cellAddress(1, $paneCol), 'pane' => 'topRight', 'sqref' => Excel::cellAddress(1, $paneCol)],
'_attr' => ['pane' => 'topRight', 'activeCell' => $activeCell, 'sqref' => $activeRef],
],
];
}
else {
// not frozen
$activeCell = $this->activeCell ?? $this->minCell();
$activeRef = $this->activeRef ?? $activeCell;
$result[$n]['_items'] = [
[
'_tag' => 'selection',
'_attr' => ['activeCell' => $activeCell, 'pane' => 'topLeft', 'sqref' => $activeCell],
'_attr' => ['pane' => 'topLeft', 'activeCell' => $activeCell, 'sqref' => $activeRef],
],
];
}
Expand Down

0 comments on commit 0b991ed

Please sign in to comment.