Expose sheet title maximum length as `Worksheet::SHEET_TITLE_MAXIMUM_LENGTH`

Closes #482
This commit is contained in:
Chris Wild 2018-05-01 09:15:44 +01:00 committed by Adrien Crivelli
parent 83c759e951
commit 275c35c877
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
2 changed files with 14 additions and 6 deletions

View File

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- 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)
- Expose sheet title maximum length as `Worksheet::SHEET_TITLE_MAXIMUM_LENGTH` - [#482](https://github.com/PHPOffice/PhpSpreadsheet/issues/482)
### Fixed

View File

@ -37,6 +37,13 @@ class Worksheet implements IComparable
const SHEETSTATE_HIDDEN = 'hidden';
const SHEETSTATE_VERYHIDDEN = 'veryHidden';
/**
* Maximum 31 characters allowed for sheet title.
*
* @var int
*/
const SHEET_TITLE_MAXIMUM_LENGTH = 31;
/**
* Invalid characters in sheet title.
*
@ -434,9 +441,9 @@ class Worksheet implements IComparable
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 > self::SHEET_TITLE_MAXIMUM_LENGTH) {
throw new Exception('Maximum ' . self::SHEET_TITLE_MAXIMUM_LENGTH . ' characters allowed in sheet code name.');
}
return $pValue;
@ -458,9 +465,9 @@ class Worksheet implements IComparable
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) > self::SHEET_TITLE_MAXIMUM_LENGTH) {
throw new Exception('Maximum ' . self::SHEET_TITLE_MAXIMUM_LENGTH . ' characters allowed in sheet title.');
}
return $pValue;