diff --git a/src/PhpSpreadsheet/Worksheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet/Worksheet.php index 7afa82b5d9..39355b3c4f 100644 --- a/src/PhpSpreadsheet/Worksheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet/Worksheet.php @@ -3682,7 +3682,9 @@ public function applyStylesFromArray(string $coordinate, array $styleArray): boo } $activeSheetIndex = $spreadsheet->getActiveSheetIndex(); $originalSelected = $this->selectedCells; + $originalActive = $this->activeCell; $this->getStyle($coordinate)->applyFromArray($styleArray); + $this->activeCell = $originalActive; $this->selectedCells = $originalSelected; if ($activeSheetIndex >= 0) { $spreadsheet->setActiveSheetIndex($activeSheetIndex); diff --git a/tests/PhpSpreadsheetTests/Worksheet/Issue4128Test.php b/tests/PhpSpreadsheetTests/Worksheet/Issue4128Test.php new file mode 100644 index 0000000000..4636310a9f --- /dev/null +++ b/tests/PhpSpreadsheetTests/Worksheet/Issue4128Test.php @@ -0,0 +1,23 @@ +getActiveSheet(); + self::assertSame('A1', $sheet->getActiveCell()); + self::assertSame('A1', $sheet->getSelectedCells()); + $sheet->setCellValue('D1', 'MyDate'); + self::assertSame('A1', $sheet->getActiveCell()); + self::assertSame('A1', $sheet->getSelectedCells()); + $spreadsheet->disconnectWorksheets(); + } +}