Skip to content

Commit

Permalink
Merge pull request #4132 from oleibman/issue4128
Browse files Browse the repository at this point in the history
Worksheet applyStylesFromArray Retain Active Cell
  • Loading branch information
oleibman authored Aug 8, 2024
2 parents 1c77e00 + 905d93f commit ffbcee6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com)
and this project adheres to [Semantic Versioning](https://semver.org).

## TBD - 3.0.0
## 2024-08-07 - 2.2.2

### Added

Expand All @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- RATE Function Floating Point Number of Periods. [PR #4107](https://github.com/PHPOffice/PhpSpreadsheet/pull/4107)
- Parameter Name Change Xlsx Writer Workbook. [Issue #4108](https://github.com/PHPOffice/PhpSpreadsheet/issues/4108) [PR #4111](https://github.com/PHPOffice/PhpSpreadsheet/pull/4111)
- New Algorithm for TRUNC, ROUNDUP, ROUNDDOWN. [Issue #4113](https://github.com/PHPOffice/PhpSpreadsheet/issues/4113) [PR #4115](https://github.com/PHPOffice/PhpSpreadsheet/pull/4115)
- 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)

## 2024-07-29 - 2.2.1

Expand Down
2 changes: 2 additions & 0 deletions src/PhpSpreadsheet/Worksheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions tests/PhpSpreadsheetTests/Worksheet/Issue4128Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Worksheet;

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;

class Issue4128Test extends TestCase
{
public function testIssue4128(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->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();
}
}

0 comments on commit ffbcee6

Please sign in to comment.