From 275c35c8775e3c0a5bb8d46e0316eb207cfa059d Mon Sep 17 00:00:00 2001 From: Chris Wild Date: Tue, 1 May 2018 09:15:44 +0100 Subject: [PATCH] Expose sheet title maximum length as `Worksheet::SHEET_TITLE_MAXIMUM_LENGTH` Closes #482 --- CHANGELOG.md | 1 + src/PhpSpreadsheet/Worksheet/Worksheet.php | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 017efb37..78c62598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/PhpSpreadsheet/Worksheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet/Worksheet.php index 156a360c..a0c8f6af 100644 --- a/src/PhpSpreadsheet/Worksheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet/Worksheet.php @@ -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;