Skip to content

Commit 275c35c

Browse files
cwildPowerKiKi
authored andcommitted
Expose sheet title maximum length as Worksheet::SHEET_TITLE_MAXIMUM_LENGTH
Closes #482
1 parent 83c759e commit 275c35c

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
### Added
1212

1313
- Support to read Xlsm templates with form elements, macros, printer settings, protected elements and back compatibility drawing, and save result without losing important elements of document - [#435](https://github.com/PHPOffice/PhpSpreadsheet/issues/435)
14+
- Expose sheet title maximum length as `Worksheet::SHEET_TITLE_MAXIMUM_LENGTH` - [#482](https://github.com/PHPOffice/PhpSpreadsheet/issues/482)
1415

1516
### Fixed
1617

src/PhpSpreadsheet/Worksheet/Worksheet.php

+13-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ class Worksheet implements IComparable
3737
const SHEETSTATE_HIDDEN = 'hidden';
3838
const SHEETSTATE_VERYHIDDEN = 'veryHidden';
3939

40+
/**
41+
* Maximum 31 characters allowed for sheet title.
42+
*
43+
* @var int
44+
*/
45+
const SHEET_TITLE_MAXIMUM_LENGTH = 31;
46+
4047
/**
4148
* Invalid characters in sheet title.
4249
*
@@ -434,9 +441,9 @@ private static function checkSheetCodeName($pValue)
434441
throw new Exception('Invalid character found in sheet code name');
435442
}
436443

437-
// Maximum 31 characters allowed for sheet title
438-
if ($CharCount > 31) {
439-
throw new Exception('Maximum 31 characters allowed in sheet code name.');
444+
// Enforce maximum characters allowed for sheet title
445+
if ($CharCount > self::SHEET_TITLE_MAXIMUM_LENGTH) {
446+
throw new Exception('Maximum ' . self::SHEET_TITLE_MAXIMUM_LENGTH . ' characters allowed in sheet code name.');
440447
}
441448

442449
return $pValue;
@@ -458,9 +465,9 @@ private static function checkSheetTitle($pValue)
458465
throw new Exception('Invalid character found in sheet title');
459466
}
460467

461-
// Maximum 31 characters allowed for sheet title
462-
if (Shared\StringHelper::countCharacters($pValue) > 31) {
463-
throw new Exception('Maximum 31 characters allowed in sheet title.');
468+
// Enforce maximum characters allowed for sheet title
469+
if (Shared\StringHelper::countCharacters($pValue) > self::SHEET_TITLE_MAXIMUM_LENGTH) {
470+
throw new Exception('Maximum ' . self::SHEET_TITLE_MAXIMUM_LENGTH . ' characters allowed in sheet title.');
464471
}
465472

466473
return $pValue;

0 commit comments

Comments
 (0)