diff options
| -rw-r--r-- | lib/axlsx/workbook/defined_name.rb | 17 | ||||
| -rw-r--r-- | test/workbook/tc_defined_name.rb | 16 |
2 files changed, 21 insertions, 12 deletions
diff --git a/lib/axlsx/workbook/defined_name.rb b/lib/axlsx/workbook/defined_name.rb index 3a606024..32b6fe52 100644 --- a/lib/axlsx/workbook/defined_name.rb +++ b/lib/axlsx/workbook/defined_name.rb @@ -24,16 +24,16 @@ # </xsd:simpleContent> module Axlsx - # This element defines the defined names that are defined within this workbook. + # This element defines the defined names that are defined within this workbook. # Defined names are descriptive text that is used to represents a cell, range of cells, formula, or constant value. # Use easy-to-understand names, such as Products, to refer to hard to understand ranges, such as Sales!C20:C30. - # A defined name in a formula can make it easier to understand the purpose of the formula. + # A defined name in a formula can make it easier to understand the purpose of the formula. # @example # The formula =SUM(FirstQuarterSales) might be easier to identify than =SUM(C20:C30 # # Names are available to any sheet. # @example - # If the name ProjectedSales refers to the range A20:A30 on the first worksheet in a workbook, + # If the name ProjectedSales refers to the range A20:A30 on the first worksheet in a workbook, # you can use the name ProjectedSales on any other sheet in the same workbook to refer to range A20:A30 on the first worksheet. # Names can also be used to represent formulas or values that do not change (constants). # @@ -71,7 +71,7 @@ module Axlsx # applied. This represents the source data range, unfiltered. # b. This defined name refers to a range to which an AutoFilter has been # applied. - # _xlnm.Extract: this defined name refers to the range containing the filtered output + # _xlnm.Extract: this defined name refers to the range containing the filtered output # values resulting from applying an advanced filter criteria to a source range. # Miscellaneous # _xlnm.Consolidate_Area: the defined name refers to a consolidation area. @@ -88,14 +88,14 @@ module Axlsx # This attribute is used when there is an add-in or other code project associated with the file. # @option [Boolean] vb_proceedure - Specifies a boolean value that indicates whether the defined name is related to an external function, command, or other executable code. # @option [Boolean] xlm - Specifies a boolean value that indicates whether the defined name is related to an external function, command, or other executable code. - # @option [Integer] function_group_id - Specifies the function group index if the defined name refers to a function. + # @option [Integer] function_group_id - Specifies the function group index if the defined name refers to a function. # The function group defines the general category for the function. # This attribute is used when there is an add-in or other code project associated with the file. # See Open Office XML Part 1 for more info. # @option [String] short_cut_key - Specifies the keyboard shortcut for the defined name. - # @option [Boolean] publish_to_server - Specifies a boolean value that indicates whether the defined name is included in the + # @option [Boolean] publish_to_server - Specifies a boolean value that indicates whether the defined name is included in the # version of the workbook that is published to or rendered on a Web or application server. - # @option [Boolean] workbook_parameter - Specifies a boolean value that indicates that the name is used as a workbook parameter on a + # @option [Boolean] workbook_parameter - Specifies a boolean value that indicates that the name is used as a workbook parameter on a # version of the workbook that is published to or rendered on a Web or application server. def initialize(formula, options={}) @formula = formula @@ -119,8 +119,9 @@ module Axlsx :workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden, :name, :local_sheet_id def to_xml_string(str='') - raise ArgumentError, 'you must specify the name for this defined name. Please read the documentation for Axlsx::DefinedName for more details' unless name + raise ArgumentError, 'you must specify the name for this defined name. Please read the documentation for Axlsx::DefinedName for more details' unless name str << '<definedName ' + str << 'name="' << name << '" ' serialized_attributes str str << '>' << @formula str << '</definedName>' diff --git a/test/workbook/tc_defined_name.rb b/test/workbook/tc_defined_name.rb index b16b3346..4da31eb8 100644 --- a/test/workbook/tc_defined_name.rb +++ b/test/workbook/tc_defined_name.rb @@ -1,14 +1,14 @@ require 'tc_helper' class TestDefinedNames < Test::Unit::TestCase - def setup + def setup @dn = Axlsx::DefinedName.new('Sheet1!A1:A1') end def test_initialize assert_equal('Sheet1!A1:A1', @dn.formula) end - + def test_string_attributes %w(short_cut_key status_bar help description custom_menu comment).each do |attr| assert_raise(ArgumentError, 'only strings allowed in string attributes') { @dn.send("#{attr}=", 1) } @@ -29,13 +29,21 @@ class TestDefinedNames < Test::Unit::TestCase assert_nothing_raised { @dn.local_sheet_id = 1 } end + def test_do_not_camelcase_value_for_name + @dn.name = '_xlnm._FilterDatabase' + doc = Nokogiri::XML(@dn.to_xml_string) + assert_equal(doc.xpath("//definedName[@name='_xlnm._FilterDatabase']").size, 1) + assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text) + end + def test_to_xml_string assert_raise(ArgumentError, 'name is required for serialization') { @dn.to_xml_string } @dn.name = '_xlnm.Print_Titles' @dn.hidden = true doc = Nokogiri::XML(@dn.to_xml_string) - assert(doc.xpath("//definedName[@name='_xlnm.Print_Titles']")) - assert(doc.xpath("//definedName[@hidden='true']")) + assert_equal(doc.xpath("//definedName[@name='_xlnm.Print_Titles']").size, 1) + assert_equal(doc.xpath("//definedName[@hidden='true']").size, 1) assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text) end + end |
