Skip to content

Commit

Permalink
Retain activeCell
Browse files Browse the repository at this point in the history
  • Loading branch information
oleibman committed Aug 7, 2024
1 parent 6153b30 commit 23cb107
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/PhpSpreadsheet/Worksheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ public function calculateColumnWidths(): static
{
$activeSheet = $this->getParent()?->getActiveSheetIndex();
$selectedCells = $this->selectedCells;
$activeCell = $this->activeCell;
// initialize $autoSizes array
$autoSizes = [];
foreach ($this->getColumnDimensions() as $colDimension) {
Expand Down Expand Up @@ -786,6 +787,7 @@ public function calculateColumnWidths(): static
$this->getParent()?->setActiveSheetIndex($activeSheet);
}
$this->selectedCells = $selectedCells;
$this->activeCell = $activeCell;

return $this;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/PhpSpreadsheetTests/Writer/RetainSelectedCellsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public function testRetainAutoSize(string $type): void
$sheet2->setSelectedCells('C3');
$sheet3->setSelectedCells('D4');
$spreadsheet->setActiveSheetIndex(1);
$activeCellSheet1 = $sheet1->getActiveCell();
$activeCellSheet2 = $sheet2->getActiveCell();
$activeCellSheet3 = $sheet3->getActiveCell();

$this->fileName = File::temporaryFilename();
$writer = IOFactory::createWriter($spreadsheet, $type);
Expand All @@ -124,6 +127,9 @@ public function testRetainAutoSize(string $type): void
self::assertSame('B2', $spreadsheet->getSheet(0)->getSelectedCells());
self::assertSame('C3', $spreadsheet->getSheet(1)->getSelectedCells());
self::assertSame('D4', $spreadsheet->getSheet(2)->getSelectedCells());
self::assertSame($activeCellSheet1, $spreadsheet->getSheet(0)->getActiveCell());
self::assertSame($activeCellSheet2, $spreadsheet->getSheet(1)->getActiveCell());
self::assertSame($activeCellSheet3, $spreadsheet->getSheet(2)->getActiveCell());

$spreadsheet->disconnectWorksheets();
}
Expand Down

0 comments on commit 23cb107

Please sign in to comment.