Skip to content

Commit

Permalink
Merge pull request #4330 from oleibman/removewsstyles
Browse files Browse the repository at this point in the history
Remove Styles Property From Worksheet
  • Loading branch information
oleibman authored Feb 5, 2025
2 parents eafbed6 + dd8fee5 commit 6abfe2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
25 changes: 4 additions & 21 deletions src/PhpSpreadsheet/Worksheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Worksheet
/**
* Invalid characters in sheet title.
*/
private static array $invalidCharacters = ['*', ':', '/', '\\', '?', '[', ']'];
private const INVALID_CHARACTERS = ['*', ':', '/', '\\', '?', '[', ']'];

/**
* Parent spreadsheet.
Expand Down Expand Up @@ -157,13 +157,6 @@ class Worksheet
*/
private Protection $protection;

/**
* Collection of styles.
*
* @var Style[]
*/
private array $styles = [];

/**
* Conditional styles. Indexed by cell coordinate, e.g. 'A1'.
*/
Expand Down Expand Up @@ -400,7 +393,7 @@ public function getCellCollection(): Cells
*/
public static function getInvalidCharacters(): array
{
return self::$invalidCharacters;
return self::INVALID_CHARACTERS;
}

/**
Expand All @@ -418,7 +411,7 @@ private static function checkSheetCodeName(string $sheetCodeName): string
}
// Some of the printable ASCII characters are invalid: * : / \ ? [ ] and first and last characters cannot be a "'"
if (
(str_replace(self::$invalidCharacters, '', $sheetCodeName) !== $sheetCodeName)
(str_replace(self::INVALID_CHARACTERS, '', $sheetCodeName) !== $sheetCodeName)
|| (Shared\StringHelper::substring($sheetCodeName, -1, 1) == '\'')
|| (Shared\StringHelper::substring($sheetCodeName, 0, 1) == '\'')
) {
Expand All @@ -443,7 +436,7 @@ private static function checkSheetCodeName(string $sheetCodeName): string
private static function checkSheetTitle(string $sheetTitle): string
{
// Some of the printable ASCII characters are invalid: * : / \ ? [ ]
if (str_replace(self::$invalidCharacters, '', $sheetTitle) !== $sheetTitle) {
if (str_replace(self::INVALID_CHARACTERS, '', $sheetTitle) !== $sheetTitle) {
throw new Exception('Invalid character found in sheet title');
}

Expand Down Expand Up @@ -1393,16 +1386,6 @@ public function getColumnStyle(string $column): ?Style
);
}

/**
* Get styles.
*
* @return Style[]
*/
public function getStyles(): array
{
return $this->styles;
}

/**
* Get style for cell.
*
Expand Down
13 changes: 11 additions & 2 deletions tests/PhpSpreadsheetTests/Worksheet/Worksheet2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ public function testMiscellaneous(): void
$invalid = Worksheet::getInvalidCharacters();
self::assertSame(['*', ':', '/', '\\', '?', '[', ']'], $invalid);
$worksheet = new Worksheet();
self::assertEmpty($worksheet->getStyles());
$coord1 = $worksheet->getCoordinates();
self::assertSame([], $coord1);
$worksheet->getCell('B3')->setValue(1);
$worksheet->getCell('G2')->setValue(2);
$coord2 = $worksheet->getCoordinates(false); // in order added
self::assertSame(['B3', 'G2'], $coord2);
$coord3 = $worksheet->getCoordinates(); // sorted by row then column
self::assertSame(['G2', 'B3'], $coord3);
$worksheet = new Worksheet();
$worksheet->disconnectCells();
self::assertSame([], $worksheet->getCoordinates());
$coord4 = $worksheet->getCoordinates();
self::assertSame([], $coord4);
}

public function testHighestColumn(): void
Expand Down

0 comments on commit 6abfe2f

Please sign in to comment.