Merge pull request #3220 from PHPOffice/Issue-3214_Xlsx-Reader-Adjusts-Selected-Cell-when-Loading-CF-Ranges

Store the currently selected cell when loading Conditional Format Ranges, then reset afterwards
This commit is contained in:
Mark Baker
2022-11-30 12:07:53 +01:00
committed by GitHub
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.