diff options
| author | Geremia Taglialatela <[email protected]> | 2022-09-21 00:34:43 +0200 |
|---|---|---|
| committer | Stefan Daschek <[email protected]> | 2022-09-21 01:25:53 +0200 |
| commit | abd64701cee4f5326c18241c24f872fb96268094 (patch) | |
| tree | b84a5b23962513ce9832ff7b249529d8d6e62765 /lib/axlsx/workbook/worksheet/worksheet.rb | |
| parent | 20c7572361fa9b0ac79cc9f44ae0626aa8565cd8 (diff) | |
| download | caxlsx-abd64701cee4f5326c18241c24f872fb96268094.tar.gz caxlsx-abd64701cee4f5326c18241c24f872fb96268094.zip | |
Add worksheet name max length to a constant
Close #163
Diffstat (limited to 'lib/axlsx/workbook/worksheet/worksheet.rb')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index d782fefe..b51e2c00 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -303,7 +303,8 @@ 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 + # The name of a worksheet must be unique in the workbook, and must not exceed the number + # of characters defined in Axlsx::WORKSHEET_MAX_NAME_LENGTH # @param [String] name def name=(name) validate_sheet_name name @@ -684,7 +685,7 @@ module Axlsx # ignore first character (BOM) after encoding to utf16 because Excel does so, too. raise ArgumentError, (ERR_SHEET_NAME_EMPTY) if name.empty? character_length = name.encode("utf-16")[1..-1].encode("utf-16").bytesize / 2 - raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if character_length > 31 + raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if character_length > WORKSHEET_MAX_NAME_LENGTH raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if '[]*/\?:'.chars.any? { |char| name.include? char } name = Axlsx::coder.encode(name) sheet_names = @workbook.worksheets.reject { |s| s == self }.map { |s| s.name } |
