Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Worksheet/Issue1457Test.php
T
oleibman 05fa51581c splitRange and ProtectedRange
Fix #1457, which had gone stale but is now re-opened. The `Coordinate::splitRange` method expects a string of cell ranges, but it is a bit limited. Excel sometimes uses comma for union and space for intersection, and sometimes vice versa. `splitRange` uses comma for union, and doesn't do anything with spaces. This PR adds a new method `Coordinate::allRanges` which handles both union and intersection, and adds a parameter to indicate whether comma means union or intersection (with space meaning the other). Also, since the issue specifically mentioned this as a problem for `ProtectedRange`, an `allRanges` method is added to that class.
2025-08-10 15:05:51 -07:00

29 lines
751 B
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PHPUnit\Framework\TestCase;
class Issue1457Test extends TestCase
{
public function testIssue1457(): void
{
$sheet = new Worksheet();
$sheet->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());
}
}