Skip to content

Commit

Permalink
Merge pull request #3220 from PHPOffice/Issue-3214_Xlsx-Reader-Adjust…
Browse files Browse the repository at this point in the history
…s-Selected-Cell-when-Loading-CF-Ranges

Store the currently selected cell when loading Conditional Format Ranges, then reset afterwards
  • Loading branch information
MarkBaker authored Nov 30, 2022
2 parents 58c6e51 + c257122 commit dcb10e2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/PhpSpreadsheet/Reader/Xlsx/ConditionalStyles.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,27 @@ public function __construct(Worksheet $workSheet, SimpleXMLElement $worksheetXml

public function load(): void
{
$selectedCells = $this->worksheet->getSelectedCells();

$this->setConditionalStyles(
$this->worksheet,
$this->readConditionalStyles($this->worksheetXml),
$this->worksheetXml->extLst
);

$this->worksheet->setSelectedCells($selectedCells);
}

public function loadFromExt(StyleReader $styleReader): void
{
$selectedCells = $this->worksheet->getSelectedCells();

$this->ns = $this->worksheetXml->getNamespaces(true);
$this->setConditionalsFromExt(
$this->readConditionalsFromExt($this->worksheetXml->extLst, $styleReader)
);

$this->worksheet->setSelectedCells($selectedCells);
}

private function setConditionalsFromExt(array $conditionals): void
Expand Down
11 changes: 11 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@

class ConditionalTest extends AbstractFunctional
{
public function testLoadingConditionalDoesntLoseSelectedCell(): void
{
$filename = 'tests/data/Reader/XLSX/ConditionalFormat_Ranges.xlsx';
$reader = IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load($filename);
$worksheet = $spreadsheet->getActiveSheet();

self::assertSame('A1', $worksheet->getActiveCell());
self::assertSame('A1', $worksheet->getSelectedCells());
}

/**
* Test check if conditional style with type 'notContainsText' works on xlsx.
*/
Expand Down
Binary file not shown.

0 comments on commit dcb10e2

Please sign in to comment.