Store the currently selected cell when loading Conditional Format Ranges, then reset afterwards

This commit is contained in:
MarkBaker
2022-11-30 10:57:34 +01:00
parent 042bacf380
commit 71334877c9
3 changed files with 19 additions and 0 deletions
@@ -37,19 +37,27 @@ class ConditionalStyles
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
@@ -8,6 +8,17 @@ use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
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.
*/
Binary file not shown.