summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-07-14 13:25:52 +0900
committerRandy Morgan <[email protected]>2012-07-14 13:25:52 +0900
commitbcebd1714a5224a36e331a47880ae94dbc32054c (patch)
treef6283a0beeb98c42c8fe96d0b4e4e3e071ddf1cc /lib
parentb24833c496e84177ef1f20ea04abdfa3bc26d51c (diff)
downloadcaxlsx-bcebd1714a5224a36e331a47880ae94dbc32054c.tar.gz
caxlsx-bcebd1714a5224a36e331a47880ae94dbc32054c.zip
Additional validations for excel sheet name and example updates
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/util/constants.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb1
2 files changed, 5 insertions, 0 deletions
diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb
index 0a2b5499..e5fb08f1 100644
--- a/lib/axlsx/util/constants.rb
+++ b/lib/axlsx/util/constants.rb
@@ -249,6 +249,10 @@ module Axlsx
# 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 sheets that use a name which includes a colon
+
+ ERR_SHEET_NAME_COLON_FORBIDDEN = "Your worksheet name '%s' contains a colon, which is not allowed by MS Excel and will cause repair warnings. Please change the name of your sheet."
# 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"
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 93eb010b..68ae2e03 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -322,6 +322,7 @@ module Axlsx
def name=(v)
DataTypeValidator.validate "Worksheet.name", String, v
raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % v) if v.size > 31
+ raise ArgumentError, (ERR_SHEET_NAME_COLON_FORBIDDEN % v) if v.include? ':'
v = Axlsx::coder.encode(v)
sheet_names = @workbook.worksheets.map { |s| s.name }
raise ArgumentError, (ERR_DUPLICATE_SHEET_NAME % v) if sheet_names.include?(v)