diff --git a/CHANGELOG.md b/CHANGELOG.md index cdd03beead..867eb4d0ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org). Thia is a ### Added -- Nothing yet. +- Add Conditional Formatting with IconSet (Xlsx only). [Issue #4560](https://github.com/PHPOffice/PhpSpreadsheet/issues/4560) [PR #4574](https://github.com/PHPOffice/PhpSpreadsheet/pull/4574) +- Copy cell adjusting formula. [Issue #1203](https://github.com/PHPOffice/PhpSpreadsheet/issues/1203) [PR #4577](https://github.com/PHPOffice/PhpSpreadsheet/pull/4577) +- splitRange and ProtectedRange. [Issue #1457](https://github.com/PHPOffice/PhpSpreadsheet/issues/1457) [PR #4580](https://github.com/PHPOffice/PhpSpreadsheet/pull/4580) ### Removed @@ -29,7 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). Thia is a ### Fixed -- Nothing yet. +- Google-only formulas exported from Google Sheets. [Issue #1637](https://github.com/PHPOffice/PhpSpreadsheet/issues/1637) [PR #4579](https://github.com/PHPOffice/PhpSpreadsheet/pull/4579) ## 2025-08-10 - 5.0.0 diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php index 03c475fb66..227f2c1170 100644 --- a/src/PhpSpreadsheet/Cell/Coordinate.php +++ b/src/PhpSpreadsheet/Cell/Coordinate.php @@ -136,7 +136,8 @@ public static function absoluteCoordinate(string $cellAddress): string } /** - * Split range into coordinate strings. + * Split range into coordinate strings, using comma for union + * and ignoring intersection (space). * * @param string $range e.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4' * @@ -160,6 +161,28 @@ public static function splitRange(string $range): array return $outArray; } + /** + * Split range into coordinate strings, resolving unions and intersections. + * + * @param string $range e.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4' + * @param bool $unionIsComma true=comma is union, space is intersection + * false=space is union, comma is intersection + * + * @return array> Array containing one or more arrays containing one or two coordinate strings + * e.g. ['B4','D9'] or [['B4','D9'], ['H2','O11']] + * or ['B4'] + */ + public static function allRanges(string $range, bool $unionIsComma = true): array + { + if (!$unionIsComma) { + $range = str_replace([',', ' ', "\0"], ["\0", ',', ' '], $range); + } + + return self::splitRange( + self::resolveUnionAndIntersection($range) + ); + } + /** * Build range from coordinate strings. * diff --git a/src/PhpSpreadsheet/Worksheet/ProtectedRange.php b/src/PhpSpreadsheet/Worksheet/ProtectedRange.php index bd4197628f..13c0d50bf1 100644 --- a/src/PhpSpreadsheet/Worksheet/ProtectedRange.php +++ b/src/PhpSpreadsheet/Worksheet/ProtectedRange.php @@ -2,6 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet; +use PhpOffice\PhpSpreadsheet\Cell\Coordinate; + class ProtectedRange { private string $name = ''; @@ -42,4 +44,16 @@ public function getSecurityDescriptor(): string { return $this->securityDescriptor; } + + /** + * Split range into coordinate strings. + * + * @return array> Array containing one or more arrays containing one or two coordinate strings + * e.g. ['B4','D9'] or [['B4','D9'], ['H2','O11']] + * or ['B4'] + */ + public function allRanges(): array + { + return Coordinate::allRanges($this->sqref, false); + } } diff --git a/tests/PhpSpreadsheetTests/Worksheet/Issue1457Test.php b/tests/PhpSpreadsheetTests/Worksheet/Issue1457Test.php new file mode 100644 index 0000000000..dbdead3745 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Worksheet/Issue1457Test.php @@ -0,0 +1,28 @@ +protectCells('C14:O15 C161:O1081 C16:H160 J16:O160 Q5'); + $protectedRanges = $sheet->getProtectedCellRanges(); + self::assertCount(1, $protectedRanges); + $range0 = reset($protectedRanges); + $expected = [ + ['C14', 'O15'], + ['C161', 'O1081'], + ['C16', 'H160'], + ['J16', 'O160'], + ['Q5'], + ]; + self::assertSame($expected, $range0->allRanges()); + } +}