axlsx 1.1.8 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/.yardopts +5 -2
  2. data/CHANGELOG.md +39 -0
  3. data/README.md +48 -46
  4. data/Rakefile +3 -3
  5. data/examples/basic_charts.rb +8 -0
  6. data/examples/example.rb +7 -1
  7. data/examples/example.xlsx +0 -0
  8. data/examples/example_streamed.xlsx +0 -0
  9. data/examples/no-use_autowidth.xlsx +0 -0
  10. data/examples/scraping_html.rb +91 -0
  11. data/examples/shared_strings_example.xlsx +0 -0
  12. data/lib/axlsx.rb +14 -8
  13. data/lib/axlsx/drawing/bar_3D_chart.rb +2 -8
  14. data/lib/axlsx/drawing/chart.rb +29 -25
  15. data/lib/axlsx/drawing/d_lbls.rb +100 -0
  16. data/lib/axlsx/drawing/drawing.rb +2 -0
  17. data/lib/axlsx/drawing/line_3D_chart.rb +2 -9
  18. data/lib/axlsx/drawing/pie_3D_chart.rb +3 -0
  19. data/lib/axlsx/drawing/scatter_chart.rb +2 -8
  20. data/lib/axlsx/drawing/two_cell_anchor.rb +38 -1
  21. data/lib/axlsx/util/simple_typed_list.rb +13 -6
  22. data/lib/axlsx/version.rb +2 -7
  23. data/lib/axlsx/workbook/defined_name.rb +174 -0
  24. data/lib/axlsx/workbook/defined_names.rb +21 -0
  25. data/lib/axlsx/workbook/workbook.rb +39 -13
  26. data/lib/axlsx/workbook/worksheet/auto_filter.rb +34 -0
  27. data/lib/axlsx/workbook/worksheet/cell.rb +24 -1
  28. data/lib/axlsx/workbook/worksheet/col.rb +15 -0
  29. data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
  30. data/lib/axlsx/workbook/worksheet/comments.rb +8 -0
  31. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
  32. data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
  33. data/lib/axlsx/workbook/worksheet/dimension.rb +65 -0
  34. data/lib/axlsx/workbook/worksheet/merged_cells.rb +35 -0
  35. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
  36. data/lib/axlsx/workbook/worksheet/row.rb +1 -1
  37. data/lib/axlsx/workbook/worksheet/sheet_data.rb +25 -0
  38. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +24 -0
  39. data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
  40. data/lib/axlsx/workbook/worksheet/worksheet.rb +263 -380
  41. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +57 -0
  42. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +64 -0
  43. data/test/drawing/tc_bar_series.rb +1 -1
  44. data/test/drawing/tc_chart.rb +7 -1
  45. data/test/drawing/tc_d_lbls.rb +47 -0
  46. data/test/drawing/tc_drawing.rb +5 -4
  47. data/test/drawing/tc_line_series.rb +1 -1
  48. data/test/drawing/tc_pie_3D_chart.rb +1 -1
  49. data/test/drawing/tc_pie_series.rb +1 -1
  50. data/test/drawing/tc_scatter_series.rb +1 -1
  51. data/test/drawing/tc_series.rb +1 -1
  52. data/test/tc_package.rb +16 -1
  53. data/test/workbook/tc_defined_name.rb +41 -0
  54. data/test/workbook/tc_workbook.rb +5 -3
  55. data/test/workbook/worksheet/table/tc_table.rb +0 -8
  56. data/test/workbook/worksheet/tc_cell.rb +2 -4
  57. data/test/workbook/worksheet/tc_protected_range.rb +0 -1
  58. data/test/workbook/worksheet/tc_row.rb +2 -2
  59. data/test/workbook/worksheet/tc_worksheet.rb +19 -21
  60. metadata +48 -7
@@ -0,0 +1,100 @@
1
+ module Axlsx
2
+ # There are more elements in the dLbls spec that allow for
3
+ # customizations and formatting. For now, I am just implementing the
4
+ # basics.
5
+
6
+ #The DLbls class manages serialization of data labels
7
+ # showLeaderLines and leaderLines are not currently implemented
8
+ class DLbls
9
+
10
+ # These attributes are all boolean so I'm doing a bit of a hand
11
+ # waving magic show to set up the attriubte accessors
12
+ # @note
13
+ # not all charts support all methods!
14
+ # Bar3DChart and Line3DChart and ScatterChart do not support d_lbl_pos or show_leader_lines
15
+ #
16
+ BOOLEAN_ATTRIBUTES = [:show_legend_key, :show_val, :show_cat_name, :show_ser_name, :show_percent, :show_bubble_size, :show_leader_lines]
17
+
18
+ # creates a new DLbls object
19
+ def initialize(chart_type, options={})
20
+ raise ArgumentError, 'chart_type must inherit from Chart' unless chart_type.superclass == Chart
21
+ @chart_type = chart_type
22
+ initialize_defaults
23
+ options.each do |o|
24
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
25
+ end
26
+ end
27
+
28
+ # Initialize all the values to false as Excel requires them to
29
+ # explicitly be disabled or all will show.
30
+ def initialize_defaults
31
+ BOOLEAN_ATTRIBUTES.each do |attr|
32
+ self.send("#{attr}=", false)
33
+ end
34
+ end
35
+
36
+ # The chart type that is using this data lables instance.
37
+ # This affects the xml output as not all chart types support the
38
+ # same data label attributes.
39
+ attr_reader :chart_type
40
+
41
+ # The position of the data labels in the chart
42
+ # @see d_lbl_pos= for a list of allowed values
43
+ # @return [Symbol]
44
+ def d_lbl_pos
45
+ return unless @chart_type == Pie3DChart
46
+ @d_lbl_pos ||= :bestFit
47
+ end
48
+
49
+ # @see DLbls#d_lbl_pos
50
+ # Assigns the label postion for this data labels on this chart.
51
+ # Allowed positions are :bestFilt, :b, :ctr, :inBase, :inEnd, :l,
52
+ # :outEnd, :r and :t
53
+ # The default is :bestFit
54
+ # @param [Symbol] label_position the postion you want to use.
55
+ def d_lbl_pos=(label_position)
56
+ return unless @chart_type == Pie3DChart
57
+ Axlsx::RestrictionValidator.validate 'DLbls#d_lbl_pos', [:bestFit, :b, :ctr, :inBase, :inEnd, :l, :outEnd, :r, :t], label_position
58
+ @d_lbl_pos = label_position
59
+ end
60
+
61
+ # Dynamically create accessors for boolean attriubtes
62
+ BOOLEAN_ATTRIBUTES.each do |attr|
63
+ class_eval %{
64
+ # The #{attr} attribute reader
65
+ # @return [Boolean]
66
+ attr_reader :#{attr}
67
+
68
+ # The #{attr} writer
69
+ # @param [Boolean] value The value to assign to #{attr}
70
+ # @return [Boolean]
71
+ def #{attr}=(value)
72
+ Axlsx::validate_boolean(value)
73
+ @#{attr} = value
74
+ end
75
+ }
76
+ end
77
+
78
+
79
+ # serializes the data labels
80
+ # @return [String]
81
+ def to_xml_string(str = '')
82
+ validate_attributes_for_chart_type
83
+ str << '<c:dLbls>'
84
+ %w(d_lbl_pos show_legend_key show_val show_cat_name show_ser_name show_percent show_bubble_size show_leader_lines).each do |key|
85
+ next unless instance_values.keys.include?(key) && instance_values[key] != nil
86
+ str << "<c:#{Axlsx::camel(key, false)} val='#{instance_values[key]}' />"
87
+ end
88
+ str << '</c:dLbls>'
89
+ end
90
+
91
+ # nills out d_lbl_pos and show_leader_lines as these attributes, while valid in the spec actually chrash excel for any chart type other than pie charts.
92
+ def validate_attributes_for_chart_type
93
+ return if @chart_type == Pie3DChart
94
+ @d_lbl_pos = nil
95
+ @show_leader_lines = nil
96
+ end
97
+
98
+
99
+ end
100
+ end
@@ -1,5 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
+ require 'axlsx/drawing/d_lbls.rb'
3
4
  require 'axlsx/drawing/title.rb'
4
5
  require 'axlsx/drawing/series_title.rb'
5
6
  require 'axlsx/drawing/series.rb'
@@ -69,6 +70,7 @@ module Axlsx
69
70
  @anchors = SimpleTypedList.new [TwoCellAnchor, OneCellAnchor]
70
71
  end
71
72
 
73
+
72
74
  # Adds an image to the chart If th end_at option is specified we create a two cell anchor. By default we use a one cell anchor.
73
75
  # @note The recommended way to manage images is to use Worksheet.add_image. Please refer to that method for documentation.
74
76
  # @see Worksheet#add_image
@@ -71,6 +71,7 @@ module Axlsx
71
71
  super(frame, options)
72
72
  @series_type = LineSeries
73
73
  @view_3D = View3D.new({:perspective=>30}.merge(options))
74
+ @d_lbls = nil
74
75
  end
75
76
 
76
77
  # @see grouping
@@ -94,14 +95,7 @@ module Axlsx
94
95
  str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
95
96
  str_inner << '<c:varyColors val="1"/>'
96
97
  @series.each { |ser| ser.to_xml_string(str_inner) }
97
- str_inner << '<c:dLbls>'
98
- str_inner << '<c:showLegendKey val="0"/>'
99
- str_inner << '<c:showVal val="0"/>'
100
- str_inner << '<c:showCatName val="0"/>'
101
- str_inner << '<c:showSerName val="0"/>'
102
- str_inner << '<c:showPercent val="0"/>'
103
- str_inner << '<c:showBubbleSize val="0"/>'
104
- str_inner << '</c:dLbls>'
98
+ @d_lbls.to_xml_string(str) if @d_lbls
105
99
  str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
106
100
  str_inner << '<c:axId val="' << @catAxId.to_s << '"/>'
107
101
  str_inner << '<c:axId val="' << @valAxId.to_s << '"/>'
@@ -112,6 +106,5 @@ module Axlsx
112
106
  @serAxis.to_xml_string str_inner
113
107
  end
114
108
  end
115
-
116
109
  end
117
110
  end
@@ -26,6 +26,7 @@ module Axlsx
26
26
  super(frame, options)
27
27
  @series_type = PieSeries
28
28
  @view_3D = View3D.new({:rot_x =>30, :perspective=>30}.merge(options))
29
+ @d_lbls = nil
29
30
  end
30
31
 
31
32
  # Serializes the object
@@ -33,9 +34,11 @@ module Axlsx
33
34
  # @return [String]
34
35
  def to_xml_string(str = '')
35
36
  super(str) do |str_inner|
37
+
36
38
  str_inner << '<c:pie3DChart>'
37
39
  str_inner << '<c:varyColors val="1"/>'
38
40
  @series.each { |ser| ser.to_xml_string(str_inner) }
41
+ d_lbls.to_xml_string(str) if @d_lbls
39
42
  str_inner << '</c:pie3DChart>'
40
43
  end
41
44
  end
@@ -29,6 +29,7 @@ module Axlsx
29
29
  @yValAxis = ValAxis.new(@yValAxId, @xValAxId)
30
30
  super(frame, options)
31
31
  @series_type = ScatterSeries
32
+ @d_lbls = nil
32
33
  options.each do |o|
33
34
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
34
35
  end
@@ -49,14 +50,7 @@ module Axlsx
49
50
  str_inner << '<c:scatterStyle val="' << scatterStyle.to_s << '"/>'
50
51
  str_inner << '<c:varyColors val="1"/>'
51
52
  @series.each { |ser| ser.to_xml_string(str_inner) }
52
- str_inner << '<c:dLbls>'
53
- str_inner << '<c:showLegendKey val="0"/>'
54
- str_inner << '<c:showVal val="0"/>'
55
- str_inner << '<c:showCatName val="0"/>'
56
- str_inner << '<c:showSerName val="0"/>'
57
- str_inner << '<c:showPercent val="0"/>'
58
- str_inner << '<c:showBubbleSize val="0"/>'
59
- str_inner << '</c:dLbls>'
53
+ d_lbls.to_xml_string(str) if @d_lbls
60
54
  str_inner << '<c:axId val="' << @xValAxId.to_s << '"/>'
61
55
  str_inner << '<c:axId val="' << @yValAxId.to_s << '"/>'
62
56
  str_inner << '</c:scatterChart>'
@@ -25,7 +25,6 @@ module Axlsx
25
25
  # @return [Drawing]
26
26
  attr_reader :drawing
27
27
 
28
-
29
28
  # Creates a new TwoCellAnchor object
30
29
  # c.start_at 5, 9
31
30
  # @param [Drawing] drawing
@@ -37,6 +36,22 @@ module Axlsx
37
36
  @from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
38
37
  end
39
38
 
39
+ # sets the col, row attributes for the from marker.
40
+ # @note The recommended way to set the start position for graphical
41
+ # objects is directly thru the object.
42
+ # @see Chart#start_at
43
+ def start_at(x, y)
44
+ set_marker_coords(x, y, from)
45
+ end
46
+
47
+ # sets the col, row attributes for the to marker
48
+ # @note the recommended way to set the to position for graphical
49
+ # objects is directly thru the object
50
+ # @see Char#end_at
51
+ def end_at(x, y)
52
+ set_marker_coords(x, y, to)
53
+ end
54
+
40
55
  # Creates a graphic frame and chart object associated with this anchor
41
56
  # @return [Chart]
42
57
  def add_chart(chart_type, options)
@@ -70,6 +85,28 @@ module Axlsx
70
85
  str << '<xdr:clientData/>'
71
86
  str << '</xdr:twoCellAnchor>'
72
87
  end
88
+ private
89
+
90
+ # parses coordinates and sets up a marker's row/col propery
91
+ def set_marker_coords(x, y, marker)
92
+ marker.col, marker.row = *parse_coord_args(x, y)
93
+ end
94
+
95
+ # handles multiple inputs for setting the position of a marker
96
+ # @see Chart#start_at
97
+ def parse_coord_args(x, y=0)
98
+ if x.is_a?(String)
99
+ x, y = *Axlsx::name_to_indices(x)
100
+ end
101
+ if x.is_a?(Cell)
102
+ x, y = *x.pos
103
+ end
104
+ if x.is_a?(Array)
105
+ x, y = *x
106
+ end
107
+ [x, y]
108
+ end
109
+
73
110
 
74
111
  end
75
112
  end
@@ -50,6 +50,18 @@ module Axlsx
50
50
  @locked_at = nil
51
51
  self
52
52
  end
53
+
54
+ # join operator
55
+ # @param [Array] v the array to join
56
+ # @raise [ArgumentError] if any of the values being joined are not
57
+ # one of the allowed types
58
+ # @return [SimpleTypedList]
59
+ def +(v)
60
+ v.each do |item|
61
+ DataTypeValidator.validate "SimpleTypedList.+", @allowed_types, item
62
+ @list << item
63
+ end
64
+ end
53
65
 
54
66
  # Concat operator
55
67
  # @param [Any] v the data to be added
@@ -60,12 +72,7 @@ module Axlsx
60
72
  @list << v
61
73
  @list.size - 1
62
74
  end
63
-
64
- # alternate of << method
65
- # @see <<
66
- def push(v)
67
- self.<< v
68
- end
75
+ alias :push :<<
69
76
 
70
77
  # delete the item from the list
71
78
  # @param [Any] v The item to be deleted.
@@ -1,10 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
-
4
- # The version of the gem
5
- # When using bunle exec rake and referencing the gem on github or locally
6
- # it will use the gemspec, which preloads this constant for the gem's version.
7
- # We check to make sure that it has not already been loaded
8
- VERSION="1.1.8" unless defined? Axlsx::VERSION
9
-
3
+ # The current version
4
+ VERSION="1.2.0"
10
5
  end
@@ -0,0 +1,174 @@
1
+ # <definedNames>
2
+ # <definedName name="_xlnm.Print_Titles" localSheetId="0">Sheet1!$1:$1</definedName>
3
+ # </definedNames>
4
+
5
+ #<xsd:complexType name="CT_DefinedName">
6
+ # <xsd:simpleContent>
7
+ # <xsd:extension base="ST_Formula">
8
+ # <xsd:attribute name="name" type="s:ST_Xstring" use="required"/>
9
+ # <xsd:attribute name="comment" type="s:ST_Xstring" use="optional"/>
10
+ # <xsd:attribute name="customMenu" type="s:ST_Xstring" use="optional"/>
11
+ # <xsd:attribute name="description" type="s:ST_Xstring" use="optional"/>
12
+ # <xsd:attribute name="help" type="s:ST_Xstring" use="optional"/>
13
+ # <xsd:attribute name="statusBar" type="s:ST_Xstring" use="optional"/>
14
+ # <xsd:attribute name="localSheetId" type="xsd:unsignedInt" use="optional"/>
15
+ # <xsd:attribute name="hidden" type="xsd:boolean" use="optional" default="false"/>
16
+ # <xsd:attribute name="function" type="xsd:boolean" use="optional" default="false"/>
17
+ # <xsd:attribute name="vbProcedure" type="xsd:boolean" use="optional" default="false"/>
18
+ # <xsd:attribute name="xlm" type="xsd:boolean" use="optional" default="false"/>
19
+ # <xsd:attribute name="functionGroupId" type="xsd:unsignedInt" use="optional"/>
20
+ # <xsd:attribute name="shortcutKey" type="s:ST_Xstring" use="optional"/>
21
+ # <xsd:attribute name="publishToServer" type="xsd:boolean" use="optional" default="false"/>
22
+ # <xsd:attribute name="workbookParameter" type="xsd:boolean" use="optional" default="false"/>
23
+ # </xsd:extenstion>
24
+ # </xsd:simpleContent>
25
+
26
+ module Axlsx
27
+ # This element defines the defined names that are defined within this workbook.
28
+ # Defined names are descriptive text that is used to represents a cell, range of cells, formula, or constant value.
29
+ # Use easy-to-understand names, such as Products, to refer to hard to understand ranges, such as Sales!C20:C30.
30
+ # A defined name in a formula can make it easier to understand the purpose of the formula.
31
+ # @example
32
+ # The formula =SUM(FirstQuarterSales) might be easier to identify than =SUM(C20:C30
33
+ #
34
+ # Names are available to any sheet.
35
+ # @example
36
+ # If the name ProjectedSales refers to the range A20:A30 on the first worksheet in a workbook,
37
+ # you can use the name ProjectedSales on any other sheet in the same workbook to refer to range A20:A30 on the first worksheet.
38
+ # Names can also be used to represent formulas or values that do not change (constants).
39
+ #
40
+ # @example
41
+ # The name SalesTax can be used to represent the sales tax amount (such as 6.2 percent) applied to sales transactions.
42
+ # You can also link to a defined name in another workbook, or define a name that refers to cells in another workbook.
43
+ #
44
+ # @example
45
+ # The formula =SUM(Sales.xls!ProjectedSales) refers to the named range ProjectedSales in the workbook named Sales.
46
+ # A compliant producer or consumer considers a defined name in the range A1-XFD1048576 to be an error.
47
+ # All other names outside this range can be defined as names and overrides a cell reference if an ambiguity exists.
48
+ #
49
+ # @example
50
+ # For clarification: LOG10 is always a cell reference, LOG10() is always formula, LOGO1000 can be a defined name that overrides a cell reference.
51
+ class DefinedName
52
+ # creates a new DefinedName.
53
+ # @param [String] formula - the formula the defined name references
54
+ # @param [Hash] options - A hash of key/value pairs that will be mapped to this instances attributes.
55
+ #
56
+ # @option [String] name - Specifies the name that appears in the user interface for the defined name.
57
+ # This attribute is required.
58
+ # The following built-in names are defined in this SpreadsheetML specification:
59
+ # Print
60
+ # _xlnm.Print_Area: this defined name specifies the workbook's print area.
61
+ # _xlnm.Print_Titles: this defined name specifies the row(s) or column(s) to repeat
62
+ # the top of each printed page.
63
+ # Filter & Advanced Filter
64
+ # _xlnm.Criteria: this defined name refers to a range containing the criteria values
65
+ # to be used in applying an advanced filter to a range of data.
66
+ # _xlnm._FilterDatabase: can be one of the following
67
+ # a. this defined name refers to a range to which an advanced filter has been
68
+ # applied. This represents the source data range, unfiltered.
69
+ # b. This defined name refers to a range to which an AutoFilter has been
70
+ # applied.
71
+ # _xlnm.Extract: this defined name refers to the range containing the filtered output
72
+ # values resulting from applying an advanced filter criteria to a source range.
73
+ # Miscellaneous
74
+ # _xlnm.Consolidate_Area: the defined name refers to a consolidation area.
75
+ # _xlnm.Database: the range specified in the defined name is from a database data source.
76
+ # _xlnm.Sheet_Title: the defined name refers to a sheet title.
77
+ # @option [String] comment - A comment to optionally associate with the name
78
+ # @option [String] custom_menu - The menu text for the defined name
79
+ # @option [String] description - An optional description for the defined name
80
+ # @option [String] help - The help topic to display for this defined name
81
+ # @option [String] status_bar - The text to display on the application status bar when this defined name has focus
82
+ # @option [String] local_sheet_id - Specifies the sheet index in this workbook where data from an external reference is displayed
83
+ # @option [Boolean] hidden - Specifies a boolean value that indicates whether the defined name is hidden in the user interface.
84
+ # @option [Boolean] function - Specifies a boolean value that indicates that the defined name refers to a user-defined function.
85
+ # This attribute is used when there is an add-in or other code project associated with the file.
86
+ # @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.
87
+ # @option [Boolean] xlm - Specifies a boolean value that indicates whether the defined name is related to an external function, command, or other executable code.
88
+ # @option [Integer] function_group_id - Specifies the function group index if the defined name refers to a function.
89
+ # The function group defines the general category for the function.
90
+ # This attribute is used when there is an add-in or other code project associated with the file.
91
+ # See Open Office XML Part 1 for more info.
92
+ # @option [String] short_cut_key - Specifies the keyboard shortcut for the defined name.
93
+ # @option [Boolean] publish_to_server - Specifies a boolean value that indicates whether the defined name is included in the
94
+ # version of the workbook that is published to or rendered on a Web or application server.
95
+ # @option [Boolean] workbook_parameter - Specifies a boolean value that indicates that the name is used as a workbook parameter on a
96
+ # version of the workbook that is published to or rendered on a Web or application server.
97
+ def initialize(formula, options={})
98
+ @formula = formula
99
+ options.each do |o|
100
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
101
+ end
102
+ end
103
+ attr_reader :local_sheet_id
104
+
105
+ # The local sheet index (0-based)
106
+ # @param [Integer] value the unsinged integer index of the sheet this defined_name applies to.
107
+ def local_sheet_id=(value)
108
+ Axlsx::validate_unsigned_int(value)
109
+ @local_sheet_id = value
110
+ end
111
+
112
+ # string attributes that will be added when this class is evaluated
113
+ STRING_ATTRIBUTES = [:short_cut_key, :status_bar, :help, :description, :custom_menu, :comment]
114
+
115
+ # boolean attributes that will be added when this class is evaluated
116
+ BOOLEAN_ATTRIBUTES = [:workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden]
117
+
118
+ # Dynamically create string attribute accessors
119
+ STRING_ATTRIBUTES.each do |attr|
120
+ class_eval %{
121
+ # The #{attr} attribute reader
122
+ # @return [String]
123
+ attr_reader :#{attr}
124
+
125
+ # The #{attr} writer
126
+ # @param [String] value The value to assign to #{attr}
127
+ # @return [String]
128
+ def #{attr}=(value)
129
+ Axlsx::validate_string(value)
130
+ @#{attr}= value
131
+ end
132
+ }
133
+ end
134
+
135
+ # Dynamically create boolean attribute accessors
136
+ BOOLEAN_ATTRIBUTES.each do |attr|
137
+ class_eval %{
138
+ # The #{attr} attribute reader
139
+ # @return [Boolean]
140
+ attr_reader :#{attr}
141
+
142
+ # The #{attr} writer
143
+ # @param [Boolean] value The value to assign to #{attr}
144
+ # @return [Boolean]
145
+ def #{attr}=(value)
146
+ Axlsx::validate_boolean(value)
147
+ @#{attr} = value
148
+ end
149
+ }
150
+ end
151
+
152
+ attr_reader :name
153
+ # The name of this defined name. Please refer to the class documentation for more information
154
+ def name=(value)
155
+ Axlsx::RestrictionValidator.validate 'DefinedName.name', %w(_xlnm.Print_Area _xlnm.Print_Titles _xlnm.Criteria _xlnm._FilterDatabase _xlnm.Extract _xlnm.Consolidate_Area _xlnm.Database _xlnm.Sheet_Title), value
156
+ @name = value
157
+ end
158
+
159
+ # The formula this defined name references
160
+ attr_reader :formula
161
+
162
+ def to_xml_string(str='')
163
+ raise ArgumentError, 'you must specify the name for this defined name. Please read the documentation for Axlsx::DefinedName for more details' unless name
164
+ str << '<definedName'
165
+ instance_values.each do |name, value|
166
+ unless name == 'formula'
167
+ str << ' ' << Axlsx::camel(name, false) << "='#{value}'"
168
+ end
169
+ end
170
+ str << '>' << @formula
171
+ str << '</definedName>'
172
+ end
173
+ end
174
+ end