summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--axlsx.gemspec2
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb6
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb11
3 files changed, 15 insertions, 4 deletions
diff --git a/axlsx.gemspec b/axlsx.gemspec
index be46cb6b..bb5c4881 100644
--- a/axlsx.gemspec
+++ b/axlsx.gemspec
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.summary = "excel OOXML (xlsx) with charts, styles, images and autowidth columns."
s.has_rdoc = 'axlsx'
s.description = <<-eof
- xlsx generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine.
+ xlsx spreadsheet generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx helps you create beautiful Office Open XML Spreadsheet documents ( Excel, Google Spreadsheet, Numbers, LibreOffice) without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine.
eof
s.files = Dir.glob("{lib/**/*,examples/**/*.rb,examples/**/*.jpeg}") + %w{ LICENSE README.md Rakefile CHANGELOG.md .yardopts }
s.test_files = Dir.glob("{test/**/*}")
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 26385573..5f650263 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -23,11 +23,11 @@ module Axlsx
# @option options [Boolean] show_gridlines indicates if gridlines should be shown for this sheet.
def initialize(wb, options={})
self.workbook = wb
- @workbook.worksheets << self
@sheet_protection = nil
initialize_page_options(options)
parse_options options
+ @workbook.worksheets << self
end
# Initalizes page margin, setup and print options
@@ -637,14 +637,14 @@ module Axlsx
end
sheet_view.show_outline_symbols = true
end
-
end
+
def validate_sheet_name(name)
DataTypeValidator.validate "Worksheet.name", String, name
raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if name.size > 31
raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if '[]*/\?:'.chars.any? { |char| name.include? char }
name = Axlsx::coder.encode(name)
- sheet_names = @workbook.worksheets.map { |s| s.name }
+ sheet_names = @workbook.worksheets.reject { |s| s == self }.map { |s| s.name }
raise ArgumentError, (ERR_DUPLICATE_SHEET_NAME % name) if sheet_names.include?(name)
end
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index 8280aca0..ed8c7cab 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -405,6 +405,11 @@ class TestWorksheet < Test::Unit::TestCase
assert_raise(ArgumentError, "worksheet name must be unique") { n = @ws.name; @ws.workbook.add_worksheet(:name=> n) }
end
+ def test_name_unique_only_checks_other_worksheet_names
+ assert_nothing_raised { @ws.name = @ws.name }
+ assert_nothing_raised { Axlsx::Package.new.workbook.add_worksheet :name => 'Sheet1' }
+ end
+
def test_name_size
assert_raise(ArgumentError, "name too long!") { @ws.name = Array.new(32, "A").join() }
assert_nothing_raised { @ws.name = Array.new(31, "A").join() }
@@ -492,4 +497,10 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal(true, @ws.sheet_view.show_outline_symbols)
end
+ def test_worksheet_does_not_get_added_to_workbook_on_initialize_failure
+ assert_equal(1, @wb.worksheets.size)
+ assert_raise(ArgumentError) { @wb.add_worksheet(:name => 'Sheet1') }
+ assert_equal(1, @wb.worksheets.size)
+ end
+
end