summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/util/constants.rb3
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb2
2 files changed, 5 insertions, 0 deletions
diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb
index b2cbad26..e9a0a02a 100644
--- a/lib/axlsx/util/constants.rb
+++ b/lib/axlsx/util/constants.rb
@@ -224,6 +224,9 @@ module Axlsx
# error message for RegexValidator
ERR_REGEX = "Invalid Data. %s does not match %s."
+ # error message for sheets that use a name which is longer than 31 bytes
+ ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be 31 characters (bytes) or less"
+
# error message for duplicate sheet names
ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
end
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 5284c475..a8846913 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -116,9 +116,11 @@ module Axlsx
end
# The name of the worksheet
+ # The name of a worksheet must be unique in the workbook, and must not exceed 31 characters
# @param [String] v
def name=(v)
DataTypeValidator.validate "Worksheet.name", String, v
+ raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % v) if v.size > 31
sheet_names = @workbook.worksheets.map { |s| s.name }
raise ArgumentError, (ERR_DUPLICATE_SHEET_NAME % v) if sheet_names.include?(v)
@name=v