Skip to content

Refactor sheet name length into a class constant #482

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

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 9 additions & 6 deletions src/PhpSpreadsheet/Worksheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class Worksheet implements IComparable
const SHEETSTATE_HIDDEN = 'hidden';
const SHEETSTATE_VERYHIDDEN = 'veryHidden';

// Sheet name
const SHEETNAME_MAXIMUM_LENGTH = 31;

/**
* Invalid characters in sheet title.
*
Expand Down Expand Up @@ -434,9 +437,9 @@ private static function checkSheetCodeName($pValue)
throw new Exception('Invalid character found in sheet code name');
}

// Maximum 31 characters allowed for sheet title
if ($CharCount > 31) {
throw new Exception('Maximum 31 characters allowed in sheet code name.');
// Enforce maximum characters allowed for sheet title
if ($CharCount > static::SHEETNAME_MAXIMUM_LENGTH) {
throw new Exception('Maximum ' . static::SHEETNAME_MAXIMUM_LENGTH . ' characters allowed in sheet code name.');
}

return $pValue;
Expand All @@ -458,9 +461,9 @@ private static function checkSheetTitle($pValue)
throw new Exception('Invalid character found in sheet title');
}

// Maximum 31 characters allowed for sheet title
if (Shared\StringHelper::countCharacters($pValue) > 31) {
throw new Exception('Maximum 31 characters allowed in sheet title.');
// Enforce maximum characters allowed for sheet title
if (Shared\StringHelper::countCharacters($pValue) > static::SHEETNAME_MAXIMUM_LENGTH) {
throw new Exception('Maximum ' . static::SHEETNAME_MAXIMUM_LENGTH . ' characters allowed in sheet title.');
}

return $pValue;
Expand Down