Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ and this project adheres to [Semantic Versioning](https://semver.org). Thia is a

### Fixed

- Performance improvement when working with large amounts of cells. [Issue #4607](https://github.com/PHPOffice/PhpSpreadsheet/issues/4607) [PR #4609](https://github.com/PHPOffice/PhpSpreadsheet/pull/4609)
- Minor improvements to Calculation coverage. [PR #4624](https://github.com/PHPOffice/PhpSpreadsheet/pull/4624)
- Conditional formatting in extLst. [Issue #4629](https://github.com/PHPOffice/PhpSpreadsheet/issues/4629) [PR #4633](https://github.com/PHPOffice/PhpSpreadsheet/pull/4633)
- Php8.5 deprecates use of null as array index. [PR #4634](https://github.com/PHPOffice/PhpSpreadsheet/pull/4634)

## 2025-09-03 - 5.1.0
Expand Down
10 changes: 10 additions & 0 deletions src/PhpSpreadsheet/Reader/Xlsx/ConditionalStyles.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ private function setConditionalsFromExt(array $conditionals): void
ksort($cfRules);
// Priority is used as the key for sorting; but may not start at 0,
// so we use array_values to reset the index after sorting.
$existing = $this->worksheet->getConditionalStylesCollection();
if (array_key_exists($conditionalRange, $existing)) {
$conditionalStyle = $existing[$conditionalRange];
$cfRules = array_merge($conditionalStyle, $cfRules);
}
$this->worksheet->getStyle($conditionalRange)
->setConditionalStyles(array_values($cfRules));
}
Expand Down Expand Up @@ -133,6 +138,7 @@ private function readConditionalRuleFromExt(SimpleXMLElement $cfRuleXml, SimpleX
$conditionType = (string) $attributes->type;
$operatorType = (string) $attributes->operator;
$priority = (int) (string) $attributes->priority;
$stopIfTrue = (int) (string) $attributes->stopIfTrue;

$operands = [];
foreach ($cfRuleXml->children($this->ns['xm']) as $cfRuleOperandsXml) {
Expand All @@ -143,6 +149,7 @@ private function readConditionalRuleFromExt(SimpleXMLElement $cfRuleXml, SimpleX
$conditional->setConditionType($conditionType);
$conditional->setOperatorType($operatorType);
$conditional->setPriority($priority);
$conditional->setStopIfTrue($stopIfTrue === 1);
if (
$conditionType === Conditional::CONDITION_CONTAINSTEXT
|| $conditionType === Conditional::CONDITION_NOTCONTAINSTEXT
Expand All @@ -169,6 +176,9 @@ private function readStyleFromExt(SimpleXMLElement $extCfRuleXml): Style
if ($styleXML->fill) {
$this->styleReader->readFillStyle($cfStyle->getFill(), $styleXML->fill);
}
if ($styleXML->font) {
$this->styleReader->readFontStyle($cfStyle->getFont(), $styleXML->font);
}
}

return $cfStyle;
Expand Down
42 changes: 42 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4629Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
use PHPUnit\Framework\TestCase;

class Issue4629Test extends TestCase
{
public function testExternalAndInternalCondionalStyles(): void
{
$infile = 'tests/data/Reader/XLSX/issue.4629.xlsx';
$reader = new XlsxReader();
$spreadsheet = $reader->load($infile);
$sheet = $spreadsheet->getSheetByNameOrThrow('top');
$conditionals = $sheet->getStyle('A1:A20')->getConditionalStyles();
self::assertCount(3, $conditionals);

$conditional = $conditionals[0];
self::assertSame('expression', $conditional->getConditionType());
self::assertFalse($conditional->getStopIfTrue());
self::assertSame(['$A1<>$B1'], $conditional->getConditions());
self::assertSame(2, $conditional->getPriority());

$conditional = $conditionals[1];
self::assertSame('expression', $conditional->getConditionType());
self::assertFalse($conditional->getStopIfTrue());
self::assertSame(['AND($A1="cheese", $C1="yogurt")'], $conditional->getConditions());
self::assertSame(3, $conditional->getPriority());

$conditional = $conditionals[2]; // defined within <ext>
self::assertSame('expression', $conditional->getConditionType());
self::assertTrue($conditional->getStopIfTrue());
self::assertSame(['A1<>bottom!A1'], $conditional->getConditions());
self::assertSame(1, $conditional->getPriority());
self::assertSame('FF9C5700', $conditional->getStyle()->getFont()->getColor()->getArgb());

$spreadsheet->disconnectWorksheets();
}
}
Binary file added tests/data/Reader/XLSX/issue.4629.xlsx
Binary file not shown.