axlsx 1.2.0 → 1.3.3

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 (161) hide show
  1. data/.yardopts +3 -2
  2. data/CHANGELOG.md +34 -1
  3. data/README.md +47 -33
  4. data/Rakefile +1 -1
  5. data/examples/auto_filter.rb +16 -0
  6. data/examples/basic_charts.rb +4 -0
  7. data/examples/colored_links.rb +59 -0
  8. data/examples/doc/_index.html +88 -0
  9. data/examples/doc/class_list.html +53 -0
  10. data/examples/doc/css/common.css +1 -0
  11. data/examples/doc/css/full_list.css +57 -0
  12. data/examples/doc/css/style.css +328 -0
  13. data/examples/doc/file_list.html +52 -0
  14. data/examples/doc/frames.html +28 -0
  15. data/examples/doc/index.html +88 -0
  16. data/examples/doc/js/app.js +214 -0
  17. data/examples/doc/js/full_list.js +173 -0
  18. data/examples/doc/js/jquery.js +4 -0
  19. data/examples/doc/method_list.html +52 -0
  20. data/examples/doc/top-level-namespace.html +102 -0
  21. data/examples/example.rb +447 -257
  22. data/examples/finance.rb +82 -0
  23. data/examples/hyperlinks.rb +23 -0
  24. data/examples/page_setup.rb +11 -0
  25. data/examples/skydrive/axlsx.csv +1 -0
  26. data/examples/skydrive/axlsx.xlsx +0 -0
  27. data/examples/skydrive/real_example.rb +8 -8
  28. data/examples/sprk2012/Screen Shot 2012-09-11 at 10.42.06 PM.png +0 -0
  29. data/examples/sprk2012/Screen Shot 2012-09-11 at 11.07.48 PM.png +0 -0
  30. data/examples/sprk2012/Screen Shot 2012-09-11 at 8.31.50 PM.png +0 -0
  31. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.23.27 PM.png +0 -0
  32. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.32.06 PM.png +0 -0
  33. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.33.35 PM.png +0 -0
  34. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.46.44 PM.png +0 -0
  35. data/examples/sprk2012/Screen Shot 2012-09-12 at 5.07.23 PM.png +0 -0
  36. data/examples/sprk2012/basics.rb +11 -0
  37. data/examples/sprk2012/basics.xlsx +0 -0
  38. data/examples/sprk2012/gravatar.jpeg +0 -0
  39. data/examples/sprk2012/hair_club.jpg +0 -0
  40. data/examples/sprk2012/images.rb +9 -0
  41. data/examples/{example.xlsx → sprk2012/images.xlsx} +0 -0
  42. data/examples/sprk2012/line_chart.rb +56 -0
  43. data/examples/sprk2012/line_chart.xlsx +0 -0
  44. data/examples/sprk2012/sprk2012.key +0 -0
  45. data/examples/sprk2012/styles.rb +20 -0
  46. data/examples/sprk2012/styles.xlsx +0 -0
  47. data/examples/styles.rb +62 -0
  48. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  49. data/lib/axlsx/content_type/content_type.rb +1 -1
  50. data/lib/axlsx/content_type/default.rb +6 -37
  51. data/lib/axlsx/content_type/override.rb +6 -38
  52. data/lib/axlsx/doc_props/app.rb +10 -7
  53. data/lib/axlsx/drawing/axis.rb +4 -4
  54. data/lib/axlsx/drawing/chart.rb +2 -3
  55. data/lib/axlsx/drawing/d_lbls.rb +21 -31
  56. data/lib/axlsx/drawing/drawing.rb +6 -0
  57. data/lib/axlsx/drawing/hyperlink.rb +40 -32
  58. data/lib/axlsx/drawing/marker.rb +13 -13
  59. data/lib/axlsx/drawing/num_data.rb +6 -6
  60. data/lib/axlsx/drawing/num_data_source.rb +17 -16
  61. data/lib/axlsx/drawing/one_cell_anchor.rb +20 -22
  62. data/lib/axlsx/drawing/pic.rb +25 -27
  63. data/lib/axlsx/drawing/picture_locking.rb +12 -44
  64. data/lib/axlsx/drawing/scaling.rb +13 -13
  65. data/lib/axlsx/drawing/scatter_chart.rb +3 -3
  66. data/lib/axlsx/drawing/series.rb +3 -6
  67. data/lib/axlsx/drawing/str_data.rb +3 -3
  68. data/lib/axlsx/drawing/str_val.rb +7 -8
  69. data/lib/axlsx/drawing/view_3D.rb +52 -38
  70. data/lib/axlsx/drawing/vml_shape.rb +23 -23
  71. data/lib/axlsx/package.rb +14 -17
  72. data/lib/axlsx/stylesheet/border.rb +29 -20
  73. data/lib/axlsx/stylesheet/border_pr.rb +5 -4
  74. data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
  75. data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
  76. data/lib/axlsx/stylesheet/cell_style.rb +19 -14
  77. data/lib/axlsx/stylesheet/color.rb +19 -16
  78. data/lib/axlsx/stylesheet/dxf.rb +4 -4
  79. data/lib/axlsx/stylesheet/font.rb +22 -22
  80. data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
  81. data/lib/axlsx/stylesheet/num_fmt.rb +22 -13
  82. data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
  83. data/lib/axlsx/stylesheet/styles.rb +11 -2
  84. data/lib/axlsx/stylesheet/table_style.rb +17 -16
  85. data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
  86. data/lib/axlsx/stylesheet/table_styles.rb +14 -11
  87. data/lib/axlsx/stylesheet/xf.rb +28 -26
  88. data/lib/axlsx/util/accessors.rb +49 -0
  89. data/lib/axlsx/util/constants.rb +105 -4
  90. data/lib/axlsx/util/options_parser.rb +15 -0
  91. data/lib/axlsx/util/serialized_attributes.rb +46 -0
  92. data/lib/axlsx/util/simple_typed_list.rb +16 -2
  93. data/lib/axlsx/util/validators.rb +33 -8
  94. data/lib/axlsx/version.rb +2 -2
  95. data/lib/axlsx/workbook/defined_name.rb +13 -58
  96. data/lib/axlsx/workbook/workbook.rb +33 -2
  97. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  98. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
  99. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +246 -0
  100. data/lib/axlsx/workbook/worksheet/cell.rb +82 -45
  101. data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
  102. data/lib/axlsx/workbook/worksheet/cfvos.rb +18 -0
  103. data/lib/axlsx/workbook/worksheet/col.rb +34 -27
  104. data/lib/axlsx/workbook/worksheet/color_scale.rb +7 -13
  105. data/lib/axlsx/workbook/worksheet/comment.rb +14 -11
  106. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
  107. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +27 -25
  108. data/lib/axlsx/workbook/worksheet/data_bar.rb +44 -34
  109. data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
  110. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -1
  111. data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
  112. data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
  113. data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
  114. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
  115. data/lib/axlsx/workbook/worksheet/page_setup.rb +152 -23
  116. data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
  117. data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
  118. data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
  119. data/lib/axlsx/workbook/worksheet/row.rb +48 -81
  120. data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
  121. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
  122. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +49 -4
  123. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
  124. data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
  125. data/lib/axlsx/workbook/worksheet/table.rb +22 -17
  126. data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
  127. data/lib/axlsx/workbook/worksheet/worksheet.rb +51 -14
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +79 -0
  130. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
  131. data/lib/axlsx.rb +19 -5
  132. data/test/content_type/tc_default.rb +0 -11
  133. data/test/content_type/tc_override.rb +0 -13
  134. data/test/drawing/tc_d_lbls.rb +14 -4
  135. data/test/stylesheet/tc_styles.rb +13 -0
  136. data/test/tc_axlsx.rb +20 -2
  137. data/test/tc_package.rb +1 -0
  138. data/test/util/tc_validators.rb +22 -1
  139. data/test/workbook/tc_defined_name.rb +2 -2
  140. data/test/workbook/tc_workbook.rb +15 -0
  141. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  142. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  143. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  144. data/test/workbook/worksheet/tc_cell.rb +35 -5
  145. data/test/workbook/worksheet/tc_col.rb +11 -1
  146. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  147. data/test/workbook/worksheet/tc_page_setup.rb +6 -1
  148. data/test/workbook/worksheet/tc_pane.rb +5 -45
  149. data/test/workbook/worksheet/tc_row.rb +4 -4
  150. data/test/workbook/worksheet/tc_selection.rb +9 -48
  151. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  152. data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
  153. data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +6 -1
  154. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  155. data/test/workbook/worksheet/tc_worksheet.rb +17 -3
  156. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +64 -0
  157. metadata +74 -10
  158. data/examples/example_streamed.xlsx +0 -0
  159. data/examples/no-use_autowidth.xlsx +0 -0
  160. data/examples/shared_strings_example.xlsx +0 -0
  161. data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
@@ -2,33 +2,40 @@ module Axlsx
2
2
  # There are more elements in the dLbls spec that allow for
3
3
  # customizations and formatting. For now, I am just implementing the
4
4
  # basics.
5
-
6
5
  #The DLbls class manages serialization of data labels
7
6
  # showLeaderLines and leaderLines are not currently implemented
8
7
  class DLbls
9
8
 
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
-
9
+ include Axlsx::Accessors
10
+ include Axlsx::OptionsParser
18
11
  # creates a new DLbls object
19
12
  def initialize(chart_type, options={})
20
13
  raise ArgumentError, 'chart_type must inherit from Chart' unless chart_type.superclass == Chart
21
14
  @chart_type = chart_type
22
15
  initialize_defaults
23
- options.each do |o|
24
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
25
- end
16
+ parse_options options
26
17
  end
27
18
 
19
+ # These attributes are all boolean so I'm doing a bit of a hand
20
+ # waving magic show to set up the attriubte accessors
21
+ # @note
22
+ # not all charts support all methods!
23
+ # Bar3DChart and Line3DChart and ScatterChart do not support d_lbl_pos or show_leader_lines
24
+ #
25
+ boolean_attr_accessor :show_legend_key,
26
+ :show_val,
27
+ :show_cat_name,
28
+ :show_ser_name,
29
+ :show_percent,
30
+ :show_bubble_size,
31
+ :show_leader_lines
32
+
28
33
  # Initialize all the values to false as Excel requires them to
29
34
  # explicitly be disabled or all will show.
30
35
  def initialize_defaults
31
- BOOLEAN_ATTRIBUTES.each do |attr|
36
+ [:show_legend_key, :show_val, :show_cat_name,
37
+ :show_ser_name, :show_percent, :show_bubble_size,
38
+ :show_leader_lines].each do |attr|
32
39
  self.send("#{attr}=", false)
33
40
  end
34
41
  end
@@ -58,24 +65,7 @@ module Axlsx
58
65
  @d_lbl_pos = label_position
59
66
  end
60
67
 
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
-
68
+
79
69
  # serializes the data labels
80
70
  # @return [String]
81
71
  def to_xml_string(str = '')
@@ -137,6 +137,12 @@ module Axlsx
137
137
  "#{DRAWING_RELS_PN % (index+1)}"
138
138
  end
139
139
 
140
+ # The index of a chart, image or hyperlink object this drawing contains
141
+ def index_of(object)
142
+ objects = charts + images + hyperlinks
143
+ objects.index(object)
144
+ end
145
+
140
146
  # The drawing's relationships.
141
147
  # @return [Relationships]
142
148
  def relationships
@@ -5,6 +5,29 @@ module Axlsx
5
5
  # @see {file:README} README
6
6
  class Hyperlink
7
7
 
8
+ include Axlsx::SerializedAttributes
9
+ include Axlsx::OptionsParser
10
+
11
+ #Creates a hyperlink object
12
+ # parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent
13
+ # @param [Pic] parent
14
+ # @option options [String] tooltip message shown when hyperlinked object is hovered over with mouse.
15
+ # @option options [String] tgtFrame Target frame for opening hyperlink
16
+ # @option options [String] invalidUrl supposedly use to store the href when we know it is an invalid resource.
17
+ # @option options [String] href the target resource this hyperlink links to. This is actually stored on the relationship.
18
+ # @option options [String] action A string that can be used to perform specific actions. For excel please see this reference: http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
19
+ # @option options [Boolean] endSnd terminate any sound events when processing this link
20
+ # @option options [Boolean] history include this link in the list of visited links for the applications history.
21
+ # @option options [Boolean] highlightClick indicate that the link has already been visited.
22
+ def initialize(parent, options={})
23
+ DataTypeValidator.validate "Hyperlink.parent", [Pic], parent
24
+ @parent = parent
25
+ parse_options options
26
+ yield self if block_given?
27
+ end
28
+
29
+ serializable_attributes :invalid_url, :action, :end_snd, :highlight_click, :history, :tgt_frame, :tooltip
30
+
8
31
  # The destination of the hyperlink stored in the drawing's relationships document.
9
32
  # @return [String]
10
33
  attr_accessor :href
@@ -13,7 +36,9 @@ module Axlsx
13
36
  #
14
37
  # What exactly that means is beyond me so if you ever use this, let me know!
15
38
  # @return [String]
16
- attr_accessor :invalidUrl
39
+ attr_accessor :invalid_url
40
+ alias :invalidUrl :invalid_url
41
+ alias :invalidUrl= :invalid_url=
17
42
 
18
43
  #An action to take when the link is clicked. The specification says "This can be used to specify a slide to be navigated to or a script of code to be run." but in most cases you will not need to do anything with this. MS does reserve a few interesting strings. @see http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
19
44
  # @return [String]
@@ -21,20 +46,24 @@ module Axlsx
21
46
 
22
47
  # Specifies if all sound events should be terminated when this link is clicked.
23
48
  # @return [Boolean]
24
- attr_reader :endSnd
49
+ attr_reader :end_snd
50
+ alias :endSnd :end_snd
25
51
 
26
52
  # @see endSnd
27
53
  # @param [Boolean] v The boolean value indicating the termination of playing sounds on click
28
54
  # @return [Boolean]
29
- def endSnd=(v) Axlsx::validate_boolean(v); @endSnd = v end
55
+ def end_snd=(v) Axlsx::validate_boolean(v); @end_snd = v end
56
+ alias :endSnd= :end_snd=
30
57
 
31
58
  # indicates that the link has already been clicked.
32
59
  # @return [Boolean]
33
- attr_reader :highlightClick
60
+ attr_reader :highlight_click
61
+ alias :highlightClick :highlight_click
34
62
 
35
63
  # @see highlightClick
36
64
  # @param [Boolean] v The value to assign
37
- def highlightClick=(v) Axlsx::validate_boolean(v); @highlightClick = v end
65
+ def highlight_click=(v) Axlsx::validate_boolean(v); @highlight_click = v end
66
+ alias :highlightClick= :highlight_click=
38
67
 
39
68
  # From the specs: Specifies whether to add this URI to the history when navigating to it. This allows for the viewing of this presentation without the storing of history information on the viewing machine. If this attribute is omitted, then a value of 1 or true is assumed.
40
69
  # @return [Boolean]
@@ -46,50 +75,29 @@ module Axlsx
46
75
 
47
76
  # From the specs: Specifies the target frame that is to be used when opening this hyperlink. When the hyperlink is activated this attribute is used to determine if a new window is launched for viewing or if an existing one can be used. If this attribute is omitted, than a new window is opened.
48
77
  # @return [String]
49
- attr_accessor :tgtFrame
78
+ attr_accessor :tgt_frame
79
+ alias :tgtFrame :tgt_frame
80
+ alias :tgtFrame= :tgt_frame=
50
81
 
51
82
  # Text to show when you mouse over the hyperlink. If you do not set this, the href property will be shown.
52
83
  # @return [String]
53
84
  attr_accessor :tooltip
54
85
 
55
- #Creates a hyperlink object
56
- # parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent
57
- # @param [Pic] parent
58
- # @option options [String] tooltip message shown when hyperlinked object is hovered over with mouse.
59
- # @option options [String] tgtFrame Target frame for opening hyperlink
60
- # @option options [String] invalidUrl supposedly use to store the href when we know it is an invalid resource.
61
- # @option options [String] href the target resource this hyperlink links to.
62
- # @option options [String] action A string that can be used to perform specific actions. For excel please see this reference: http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
63
- # @option options [Boolean] endSnd terminate any sound events when processing this link
64
- # @option options [Boolean] history include this link in the list of visited links for the applications history.
65
- # @option options [Boolean] highlightClick indicate that the link has already been visited.
66
- def initialize(parent, options={})
67
- DataTypeValidator.validate "Hyperlink.parent", [Pic], parent
68
- @parent = parent
69
- options.each do |o|
70
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
71
- end
72
- yield self if block_given?
73
-
74
- end
75
-
76
86
  # Serializes the object
77
87
  # @param [String] str
78
88
  # @return [String]
79
89
  def to_xml_string(str = '')
80
- h = self.instance_values.merge({:'r:id' => "rId#{id}", :'xmlns:r' => XML_NS_R })
81
- h.delete('href')
82
- h.delete('parent')
83
90
  str << '<a:hlinkClick '
84
- str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
91
+ serialized_attributes str, {:'r:id' => "rId#{id}", :'xmlns:r' => XML_NS_R }
85
92
  str << '/>'
86
93
  end
87
94
 
88
95
  private
96
+
89
97
  # The relational ID for this hyperlink
90
98
  # @return [Integer]
91
99
  def id
92
- @parent.anchor.drawing.charts.size + @parent.anchor.drawing.images.size + @parent.anchor.drawing.hyperlinks.index(self) + 1
100
+ @parent.anchor.drawing.index_of(self)+1
93
101
  end
94
102
 
95
103
  end
@@ -5,6 +5,18 @@ module Axlsx
5
5
  # @see Worksheet#add_chart
6
6
  class Marker
7
7
 
8
+ include Axlsx::OptionsParser
9
+
10
+ # Creates a new Marker object
11
+ # @option options [Integer] col
12
+ # @option options [Integer] colOff
13
+ # @option options [Integer] row
14
+ # @option options [Integer] rowOff
15
+ def initialize(options={})
16
+ @col, @colOff, @row, @rowOff = 0, 0, 0, 0
17
+ parse_options options
18
+ end
19
+
8
20
  # The column this marker anchors to
9
21
  # @return [Integer]
10
22
  attr_reader :col
@@ -21,19 +33,7 @@ module Axlsx
21
33
  # @return [Integer]
22
34
  attr_reader :rowOff
23
35
 
24
- # Creates a new Marker object
25
- # @option options [Integer] col
26
- # @option options [Integer] colOff
27
- # @option options [Integer] row
28
- # @option options [Integer] rowOff
29
- def initialize(options={})
30
- @col, @colOff, @row, @rowOff = 0, 0, 0, 0
31
- options.each do |o|
32
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
33
- end
34
- end
35
-
36
- # @see col
36
+ # @see col
37
37
  def col=(v) Axlsx::validate_unsigned_int v; @col = v end
38
38
  # @see colOff
39
39
  def colOff=(v) Axlsx::validate_int v; @colOff = v end
@@ -4,9 +4,7 @@ module Axlsx
4
4
  #This class specifies data for a particular data point. It is used for both numCache and numLit object
5
5
  class NumData
6
6
 
7
- # A string representing the format code to apply. For more information see see the SpreadsheetML numFmt element's (§18.8.30) formatCode attribute.
8
- # @return [String]
9
- attr_reader :format_code
7
+ include Axlsx::OptionsParser
10
8
 
11
9
  # creates a new NumVal object
12
10
  # @option options [String] formatCode
@@ -15,11 +13,13 @@ module Axlsx
15
13
  def initialize(options={})
16
14
  @format_code = "General"
17
15
  @pt = SimpleTypedList.new NumVal
18
- options.each do |o|
19
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
20
- end
16
+ parse_options options
21
17
  end
22
18
 
19
+ # A string representing the format code to apply. For more information see see the SpreadsheetML numFmt element's (§18.8.30) formatCode attribute.
20
+ # @return [String]
21
+ attr_reader :format_code
22
+
23
23
  # Creates the val objects for this data set. I am not overly confident this is going to play nicely with time and data types.
24
24
  # @param [Array] values An array of cells or values.
25
25
  def data=(values=[])
@@ -3,18 +3,7 @@ module Axlsx
3
3
  # A numeric data source for use by charts.
4
4
  class NumDataSource
5
5
 
6
- # The tag name to use when serializing this data source.
7
- # Only items defined in allowed_tag_names are allowed
8
- # @return [Symbol]
9
- attr_reader :tag_name
10
-
11
- attr_reader :data
12
-
13
- # allowed element tag names
14
- # @return [Array]
15
- def self.allowed_tag_names
16
- [:yVal, :val]
17
- end
6
+ include Axlsx::OptionsParser
18
7
 
19
8
  # creates a new NumDataSource object
20
9
  # @option options [Array] data An array of Cells or Numeric objects
@@ -30,12 +19,24 @@ module Axlsx
30
19
  if options[:data] && options[:data].first.is_a?(Cell)
31
20
  @f = Axlsx::cell_range(options[:data])
32
21
  end
33
- options.each do |o|
34
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
35
- end
22
+ parse_options options
23
+ end
24
+
25
+
26
+ # The tag name to use when serializing this data source.
27
+ # Only items defined in allowed_tag_names are allowed
28
+ # @return [Symbol]
29
+ attr_reader :tag_name
30
+
31
+ attr_reader :data
32
+
33
+ # allowed element tag names
34
+ # @return [Array]
35
+ def self.allowed_tag_names
36
+ [:yVal, :val]
36
37
  end
37
38
 
38
- # sets the tag name for this data source
39
+ # sets the tag name for this data source
39
40
  # @param [Symbol] v One of the allowed_tag_names
40
41
  def tag_name=(v)
41
42
  Axlsx::RestrictionValidator.validate "#{self.class.name}.tag_name", self.class.allowed_tag_names, v
@@ -6,6 +6,26 @@ module Axlsx
6
6
  # @see Worksheet#add_image
7
7
  class OneCellAnchor
8
8
 
9
+ include Axlsx::OptionsParser
10
+
11
+ # Creates a new OneCellAnchor object and an Pic associated with it.
12
+ # @param [Drawing] drawing
13
+ # @option options [Array] start_at the col, row to start at
14
+ # @option options [Integer] width
15
+ # @option options [Integer] height
16
+ # @option options [String] image_src the file location of the image you will render
17
+ # @option options [String] name the name attribute for the rendered image
18
+ # @option options [String] descr the description of the image rendered
19
+ def initialize(drawing, options={})
20
+ @drawing = drawing
21
+ @width = 0
22
+ @height = 0
23
+ drawing.anchors << self
24
+ @from = Marker.new
25
+ parse_options options
26
+ @object = Pic.new(self, options)
27
+ end
28
+
9
29
  # A marker that defines the from cell anchor. The default from column and row are 0 and 0 respectively
10
30
  # @return [Marker]
11
31
  attr_reader :from
@@ -28,27 +48,6 @@ module Axlsx
28
48
  # @return [Integer]
29
49
  attr_reader :height
30
50
 
31
-
32
- # Creates a new OneCellAnchor object and an Pic associated with it.
33
- # @param [Drawing] drawing
34
- # @option options [Array] start_at the col, row to start at
35
- # @option options [Integer] width
36
- # @option options [Integer] height
37
- # @option options [String] image_src the file location of the image you will render
38
- # @option options [String] name the name attribute for the rendered image
39
- # @option options [String] descr the description of the image rendered
40
- def initialize(drawing, options={})
41
- @drawing = drawing
42
- @width = 0
43
- @height = 0
44
- drawing.anchors << self
45
- @from = Marker.new
46
- options.each do |o|
47
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
48
- end
49
- @object = Pic.new(self, options)
50
- end
51
-
52
51
  # @see height
53
52
  def height=(v) Axlsx::validate_unsigned_int(v); @height = v; end
54
53
 
@@ -61,7 +60,6 @@ module Axlsx
61
60
  @drawing.anchors.index(self)
62
61
  end
63
62
 
64
-
65
63
  # Serializes the object
66
64
  # @param [String] str
67
65
  # @return [String]
@@ -5,6 +5,26 @@ module Axlsx
5
5
  # @see Worksheet#add_image
6
6
  class Pic
7
7
 
8
+ include Axlsx::OptionsParser
9
+
10
+ # Creates a new Pic(ture) object
11
+ # @param [Anchor] anchor the anchor that holds this image
12
+ # @option options [String] name
13
+ # @option options [String] descr
14
+ # @option options [String] image_src
15
+ # @option options [Array] start_at
16
+ # @option options [Intger] width
17
+ # @option options [Intger] height
18
+ def initialize(anchor, options={})
19
+ @anchor = anchor
20
+ @hyperlink = nil
21
+ @anchor.drawing.worksheet.workbook.images << self
22
+ parse_options options
23
+ start_at(*options[:start_at]) if options[:start_at]
24
+ yield self if block_given?
25
+ @picture_locking = PictureLocking.new(options)
26
+ end
27
+
8
28
  # allowed file extenstions
9
29
  ALLOWED_EXTENSIONS = ['gif', 'jpeg', 'png', 'jpg']
10
30
 
@@ -12,7 +32,6 @@ module Axlsx
12
32
  # @return [String]
13
33
  attr_reader :name
14
34
 
15
-
16
35
  # A description of the picture
17
36
  # @return [String]
18
37
  attr_reader :descr
@@ -29,26 +48,6 @@ module Axlsx
29
48
  # The picture locking attributes for this picture
30
49
  attr_reader :picture_locking
31
50
 
32
- # Creates a new Pic(ture) object
33
- # @param [Anchor] anchor the anchor that holds this image
34
- # @option options [String] name
35
- # @option options [String] descr
36
- # @option options [String] image_src
37
- # @option options [Array] start_at
38
- # @option options [Intger] width
39
- # @option options [Intger] height
40
- def initialize(anchor, options={})
41
- @anchor = anchor
42
- @hyperlink = nil
43
- @anchor.drawing.worksheet.workbook.images << self
44
- options.each do |o|
45
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
46
- end
47
- start_at(*options[:start_at]) if options[:start_at]
48
- yield self if block_given?
49
- @picture_locking = PictureLocking.new(options)
50
- end
51
-
52
51
  attr_reader :hyperlink
53
52
 
54
53
  # sets or updates a hyperlink for this image.
@@ -136,8 +135,8 @@ module Axlsx
136
135
  use_one_cell_anchor unless @anchor.is_a?(OneCellAnchor)
137
136
  @anchor.height = v
138
137
  end
139
-
140
- # This is a short cut method to set the start anchor position
138
+
139
+ # This is a short cut method to set the start anchor position
141
140
  # If you need finer granularity in positioning use
142
141
  # graphic_frame.anchor.from.colOff / rowOff
143
142
  # @param [Integer] x The column
@@ -148,7 +147,7 @@ module Axlsx
148
147
  @anchor.from.row = y
149
148
  @anchor.from
150
149
  end
151
-
150
+
152
151
  # noop if not using a two cell anchor
153
152
  # @param [Integer] x The column
154
153
  # @param [Integer] y The row
@@ -178,7 +177,7 @@ module Axlsx
178
177
  str << '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic>'
179
178
 
180
179
  end
181
-
180
+
182
181
  private
183
182
 
184
183
  # Changes the anchor to a one cell anchor.
@@ -186,7 +185,7 @@ module Axlsx
186
185
  return if @anchor.is_a?(OneCellAnchor)
187
186
  swap_anchor(OneCellAnchor.new(@anchor.drawing, :from => @anchor.from))
188
187
  end
189
-
188
+
190
189
  #changes the anchor type to a two cell anchor
191
190
  def use_two_cell_anchor
192
191
  return if @anchor.is_a?(TwoCellAnchor)
@@ -202,6 +201,5 @@ module Axlsx
202
201
  @anchor.drawing.anchors[@anchor.drawing.anchors.index(@anchor)] = new_anchor
203
202
  @anchor = new_anchor
204
203
  end
205
-
206
204
  end
207
205
  end
@@ -3,17 +3,17 @@ module Axlsx
3
3
  # The picture locking class defines the locking properties for pictures in your workbook.
4
4
  class PictureLocking
5
5
 
6
+ include Axlsx::OptionsParser
7
+ include Axlsx::SerializedAttributes
8
+ include Axlsx::Accessors
6
9
 
7
- attr_reader :noGrp
8
- attr_reader :noSelect
9
- attr_reader :noRot
10
- attr_reader :noChangeAspect
11
- attr_reader :noMove
12
- attr_reader :noResize
13
- attr_reader :noEditPoints
14
- attr_reader :noAdjustHandles
15
- attr_reader :noChangeArrowheads
16
- attr_reader :noChangeShapeType
10
+ boolean_attr_accessor :noGrp, :noSelect, :noRot, :noChangeAspect,
11
+ :noMove, :noResize, :noEditPoints, :noAdjustHandles,
12
+ :noChangeArrowheads, :noChangeShapeType
13
+
14
+ serializable_attributes :noGrp, :noSelect, :noRot, :noChangeAspect,
15
+ :noMove, :noResize, :noEditPoints, :noAdjustHandles,
16
+ :noChangeArrowheads, :noChangeShapeType
17
17
 
18
18
  # Creates a new PictureLocking object
19
19
  # @option options [Boolean] noGrp
@@ -28,47 +28,15 @@ module Axlsx
28
28
  # @option options [Boolean] noChangeShapeType
29
29
  def initialize(options={})
30
30
  @noChangeAspect = true
31
- options.each do |o|
32
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
33
- end
31
+ parse_options options
34
32
  end
35
33
 
36
- # @see noGrp
37
- def noGrp=(v) Axlsx::validate_boolean v; @noGrp = v end
38
-
39
- # @see noSelect
40
- def noSelect=(v) Axlsx::validate_boolean v; @noSelect = v end
41
-
42
- # @see noRot
43
- def noRot=(v) Axlsx::validate_boolean v; @noRot = v end
44
-
45
- # @see noChangeAspect
46
- def noChangeAspect=(v) Axlsx::validate_boolean v; @noChangeAspect = v end
47
-
48
- # @see noMove
49
- def noMove=(v) Axlsx::validate_boolean v; @noMove = v end
50
-
51
- # @see noResize
52
- def noResize=(v) Axlsx::validate_boolean v; @noResize = v end
53
-
54
- # @see noEditPoints
55
- def noEditPoints=(v) Axlsx::validate_boolean v; @noEditPoints = v end
56
-
57
- # @see noAdjustHandles
58
- def noAdjustHandles=(v) Axlsx::validate_boolean v; @noAdjustHandles = v end
59
-
60
- # @see noChangeArrowheads
61
- def noChangeArrowheads=(v) Axlsx::validate_boolean v; @noChangeArrowheads = v end
62
-
63
- # @see noChangeShapeType
64
- def noChangeShapeType=(v) Axlsx::validate_boolean v; @noChangeShapeType = v end
65
-
66
34
  # Serializes the object
67
35
  # @param [String] str
68
36
  # @return [String]
69
37
  def to_xml_string(str = '')
70
38
  str << '<a:picLocks '
71
- str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
39
+ serialized_attributes str
72
40
  str << '/>'
73
41
  end
74
42
 
@@ -3,6 +3,19 @@ module Axlsx
3
3
  # The Scaling class defines axis scaling
4
4
  class Scaling
5
5
 
6
+ include Axlsx::OptionsParser
7
+
8
+ # creates a new Scaling object
9
+ # @option options [Integer, Fixnum] logBase
10
+ # @option options [Symbol] orientation
11
+ # @option options [Float] max
12
+ # @option options [Float] min
13
+ def initialize(options={})
14
+ @orientation = :minMax
15
+ @logBase, @min, @max = nil, nil, nil
16
+ parse_options options
17
+ end
18
+
6
19
  # logarithmic base for a logarithmic axis.
7
20
  # must be between 2 and 1000
8
21
  # @return [Integer]
@@ -21,19 +34,6 @@ module Axlsx
21
34
  # @return [Float]
22
35
  attr_reader :min
23
36
 
24
- # creates a new Scaling object
25
- # @option options [Integer, Fixnum] logBase
26
- # @option options [Symbol] orientation
27
- # @option options [Float] max
28
- # @option options [Float] min
29
- def initialize(options={})
30
- @orientation = :minMax
31
- @logBase, @min, @max = nil, nil, nil
32
- options.each do |o|
33
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
34
- end
35
- end
36
-
37
37
  # @see logBase
38
38
  def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer, Fixnum], v, lambda { |arg| arg >= 2 && arg <= 1000}; @logBase = v; end
39
39
  # @see orientation
@@ -7,6 +7,8 @@ module Axlsx
7
7
  # @see README for an example
8
8
  class ScatterChart < Chart
9
9
 
10
+ include Axlsx::OptionsParser
11
+
10
12
  # The Style for the scatter chart
11
13
  # must be one of :none | :line | :lineMarker | :marker | :smooth | :smoothMarker
12
14
  # return [Symbol]
@@ -30,9 +32,7 @@ module Axlsx
30
32
  super(frame, options)
31
33
  @series_type = ScatterSeries
32
34
  @d_lbls = nil
33
- options.each do |o|
34
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
35
- end
35
+ parse_options options
36
36
  end
37
37
 
38
38
  # see #scatterStyle
@@ -6,6 +6,8 @@ module Axlsx
6
6
  # @see Chart#add_series
7
7
  class Series
8
8
 
9
+ include Axlsx::OptionsParser
10
+
9
11
  # The chart that owns this series
10
12
  # @return [Chart]
11
13
  attr_reader :chart
@@ -22,19 +24,15 @@ module Axlsx
22
24
  @order = nil
23
25
  self.chart = chart
24
26
  @chart.series << self
25
- options.each do |o|
26
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
27
- end
27
+ parse_options options
28
28
  end
29
29
 
30
-
31
30
  # The index of this series in the chart's series.
32
31
  # @return [Integer]
33
32
  def index
34
33
  @chart.series.index(self)
35
34
  end
36
35
 
37
-
38
36
  # The order of this series in the chart's series. By default the order is the index of the series.
39
37
  # @return [Integer]
40
38
  def order
@@ -68,5 +66,4 @@ module Axlsx
68
66
  str << '</c:ser>'
69
67
  end
70
68
  end
71
-
72
69
  end