Skip to content

Commit ffbcee6

Browse files
authored
Merge pull request #4132 from oleibman/issue4128
Worksheet applyStylesFromArray Retain Active Cell
2 parents 1c77e00 + 905d93f commit ffbcee6

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com)
66
and this project adheres to [Semantic Versioning](https://semver.org).
77

8-
## TBD - 3.0.0
8+
## 2024-08-07 - 2.2.2
99

1010
### Added
1111

@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2929
- RATE Function Floating Point Number of Periods. [PR #4107](https://github.com/PHPOffice/PhpSpreadsheet/pull/4107)
3030
- Parameter Name Change Xlsx Writer Workbook. [Issue #4108](https://github.com/PHPOffice/PhpSpreadsheet/issues/4108) [PR #4111](https://github.com/PHPOffice/PhpSpreadsheet/pull/4111)
3131
- New Algorithm for TRUNC, ROUNDUP, ROUNDDOWN. [Issue #4113](https://github.com/PHPOffice/PhpSpreadsheet/issues/4113) [PR #4115](https://github.com/PHPOffice/PhpSpreadsheet/pull/4115)
32+
- Worksheet applyStylesFromArray Retain Active Cell (Excel 16 was having a problem with some files). [Issue #4128](https://github.com/PHPOffice/PhpSpreadsheet/issues/4128) [PR #4132](https://github.com/PHPOffice/PhpSpreadsheet/pull/4132)
3233

3334
## 2024-07-29 - 2.2.1
3435

src/PhpSpreadsheet/Worksheet/Worksheet.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3682,7 +3682,9 @@ public function applyStylesFromArray(string $coordinate, array $styleArray): boo
36823682
}
36833683
$activeSheetIndex = $spreadsheet->getActiveSheetIndex();
36843684
$originalSelected = $this->selectedCells;
3685+
$originalActive = $this->activeCell;
36853686
$this->getStyle($coordinate)->applyFromArray($styleArray);
3687+
$this->activeCell = $originalActive;
36863688
$this->selectedCells = $originalSelected;
36873689
if ($activeSheetIndex >= 0) {
36883690
$spreadsheet->setActiveSheetIndex($activeSheetIndex);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
6+
7+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class Issue4128Test extends TestCase
11+
{
12+
public function testIssue4128(): void
13+
{
14+
$spreadsheet = new Spreadsheet();
15+
$sheet = $spreadsheet->getActiveSheet();
16+
self::assertSame('A1', $sheet->getActiveCell());
17+
self::assertSame('A1', $sheet->getSelectedCells());
18+
$sheet->setCellValue('D1', 'MyDate');
19+
self::assertSame('A1', $sheet->getActiveCell());
20+
self::assertSame('A1', $sheet->getSelectedCells());
21+
$spreadsheet->disconnectWorksheets();
22+
}
23+
}

0 commit comments

Comments
 (0)