Skip to content

Commit 6abfe2f

Browse files
authored
Merge pull request #4330 from oleibman/removewsstyles
Remove Styles Property From Worksheet
2 parents eafbed6 + dd8fee5 commit 6abfe2f

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

src/PhpSpreadsheet/Worksheet/Worksheet.php

+4-21
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Worksheet
6363
/**
6464
* Invalid characters in sheet title.
6565
*/
66-
private static array $invalidCharacters = ['*', ':', '/', '\\', '?', '[', ']'];
66+
private const INVALID_CHARACTERS = ['*', ':', '/', '\\', '?', '[', ']'];
6767

6868
/**
6969
* Parent spreadsheet.
@@ -157,13 +157,6 @@ class Worksheet
157157
*/
158158
private Protection $protection;
159159

160-
/**
161-
* Collection of styles.
162-
*
163-
* @var Style[]
164-
*/
165-
private array $styles = [];
166-
167160
/**
168161
* Conditional styles. Indexed by cell coordinate, e.g. 'A1'.
169162
*/
@@ -400,7 +393,7 @@ public function getCellCollection(): Cells
400393
*/
401394
public static function getInvalidCharacters(): array
402395
{
403-
return self::$invalidCharacters;
396+
return self::INVALID_CHARACTERS;
404397
}
405398

406399
/**
@@ -418,7 +411,7 @@ private static function checkSheetCodeName(string $sheetCodeName): string
418411
}
419412
// Some of the printable ASCII characters are invalid: * : / \ ? [ ] and first and last characters cannot be a "'"
420413
if (
421-
(str_replace(self::$invalidCharacters, '', $sheetCodeName) !== $sheetCodeName)
414+
(str_replace(self::INVALID_CHARACTERS, '', $sheetCodeName) !== $sheetCodeName)
422415
|| (Shared\StringHelper::substring($sheetCodeName, -1, 1) == '\'')
423416
|| (Shared\StringHelper::substring($sheetCodeName, 0, 1) == '\'')
424417
) {
@@ -443,7 +436,7 @@ private static function checkSheetCodeName(string $sheetCodeName): string
443436
private static function checkSheetTitle(string $sheetTitle): string
444437
{
445438
// Some of the printable ASCII characters are invalid: * : / \ ? [ ]
446-
if (str_replace(self::$invalidCharacters, '', $sheetTitle) !== $sheetTitle) {
439+
if (str_replace(self::INVALID_CHARACTERS, '', $sheetTitle) !== $sheetTitle) {
447440
throw new Exception('Invalid character found in sheet title');
448441
}
449442

@@ -1393,16 +1386,6 @@ public function getColumnStyle(string $column): ?Style
13931386
);
13941387
}
13951388

1396-
/**
1397-
* Get styles.
1398-
*
1399-
* @return Style[]
1400-
*/
1401-
public function getStyles(): array
1402-
{
1403-
return $this->styles;
1404-
}
1405-
14061389
/**
14071390
* Get style for cell.
14081391
*

tests/PhpSpreadsheetTests/Worksheet/Worksheet2Test.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ public function testMiscellaneous(): void
1616
$invalid = Worksheet::getInvalidCharacters();
1717
self::assertSame(['*', ':', '/', '\\', '?', '[', ']'], $invalid);
1818
$worksheet = new Worksheet();
19-
self::assertEmpty($worksheet->getStyles());
19+
$coord1 = $worksheet->getCoordinates();
20+
self::assertSame([], $coord1);
21+
$worksheet->getCell('B3')->setValue(1);
22+
$worksheet->getCell('G2')->setValue(2);
23+
$coord2 = $worksheet->getCoordinates(false); // in order added
24+
self::assertSame(['B3', 'G2'], $coord2);
25+
$coord3 = $worksheet->getCoordinates(); // sorted by row then column
26+
self::assertSame(['G2', 'B3'], $coord3);
27+
$worksheet = new Worksheet();
2028
$worksheet->disconnectCells();
21-
self::assertSame([], $worksheet->getCoordinates());
29+
$coord4 = $worksheet->getCoordinates();
30+
self::assertSame([], $coord4);
2231
}
2332

2433
public function testHighestColumn(): void

0 commit comments

Comments
 (0)