Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Styles Property From Worksheet #4330

Merged
merged 1 commit into from
Feb 5, 2025
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
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 @@ -399,7 +392,7 @@ public function getCellCollection(): Cells
*/
public static function getInvalidCharacters(): array
{
return self::$invalidCharacters;
return self::INVALID_CHARACTERS;
}

/**
Expand All @@ -417,7 +410,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 @@ -442,7 +435,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 @@ -1392,16 +1385,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
Loading