axlsx 1.2.0 → 2.0.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 (208) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +3 -2
  3. data/.yardopts_guide +19 -0
  4. data/CHANGELOG.md +64 -1
  5. data/README.md +105 -87
  6. data/Rakefile +0 -5
  7. data/examples/2010_comments.rb +17 -0
  8. data/examples/anchor_swapping.rb +28 -0
  9. data/examples/auto_filter.rb +16 -0
  10. data/examples/basic_charts.rb +4 -0
  11. data/examples/colored_links.rb +59 -0
  12. data/examples/conditional_formatting/example_conditional_formatting.rb +4 -2
  13. data/examples/example.rb +569 -258
  14. data/examples/ios_preview.rb +14 -0
  15. data/examples/page_setup.rb +11 -0
  16. data/examples/pivot_table.rb +39 -0
  17. data/examples/skydrive/real_example.rb +8 -8
  18. data/examples/styles.rb +66 -0
  19. data/examples/underline.rb +13 -0
  20. data/examples/wrap_text.rb +21 -0
  21. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  22. data/lib/axlsx/content_type/content_type.rb +1 -1
  23. data/lib/axlsx/content_type/default.rb +6 -37
  24. data/lib/axlsx/content_type/override.rb +6 -38
  25. data/lib/axlsx/doc_props/app.rb +10 -7
  26. data/lib/axlsx/doc_props/core.rb +6 -1
  27. data/lib/axlsx/drawing/axes.rb +61 -0
  28. data/lib/axlsx/drawing/axis.rb +20 -17
  29. data/lib/axlsx/drawing/bar_3D_chart.rb +31 -22
  30. data/lib/axlsx/drawing/cat_axis.rb +2 -10
  31. data/lib/axlsx/drawing/chart.rb +33 -6
  32. data/lib/axlsx/drawing/d_lbls.rb +21 -31
  33. data/lib/axlsx/drawing/drawing.rb +11 -17
  34. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  35. data/lib/axlsx/drawing/hyperlink.rb +42 -36
  36. data/lib/axlsx/drawing/line_3D_chart.rb +28 -70
  37. data/lib/axlsx/drawing/line_chart.rb +99 -0
  38. data/lib/axlsx/drawing/line_series.rb +20 -2
  39. data/lib/axlsx/drawing/marker.rb +38 -18
  40. data/lib/axlsx/drawing/num_data.rb +6 -6
  41. data/lib/axlsx/drawing/num_data_source.rb +17 -16
  42. data/lib/axlsx/drawing/one_cell_anchor.rb +28 -21
  43. data/lib/axlsx/drawing/pic.rb +43 -45
  44. data/lib/axlsx/drawing/picture_locking.rb +12 -44
  45. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -1
  46. data/lib/axlsx/drawing/scaling.rb +13 -13
  47. data/lib/axlsx/drawing/scatter_chart.rb +32 -21
  48. data/lib/axlsx/drawing/ser_axis.rb +15 -16
  49. data/lib/axlsx/drawing/series.rb +3 -6
  50. data/lib/axlsx/drawing/str_data.rb +3 -3
  51. data/lib/axlsx/drawing/str_val.rb +7 -8
  52. data/lib/axlsx/drawing/two_cell_anchor.rb +7 -27
  53. data/lib/axlsx/drawing/val_axis.rb +14 -13
  54. data/lib/axlsx/drawing/view_3D.rb +52 -38
  55. data/lib/axlsx/drawing/vml_shape.rb +20 -79
  56. data/lib/axlsx/package.rb +58 -28
  57. data/lib/axlsx/rels/relationship.rb +75 -9
  58. data/lib/axlsx/rels/relationships.rb +8 -1
  59. data/lib/axlsx/stylesheet/border.rb +29 -20
  60. data/lib/axlsx/stylesheet/border_pr.rb +5 -4
  61. data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
  62. data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
  63. data/lib/axlsx/stylesheet/cell_style.rb +19 -14
  64. data/lib/axlsx/stylesheet/color.rb +20 -17
  65. data/lib/axlsx/stylesheet/dxf.rb +4 -4
  66. data/lib/axlsx/stylesheet/font.rb +22 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
  68. data/lib/axlsx/stylesheet/num_fmt.rb +23 -14
  69. data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
  70. data/lib/axlsx/stylesheet/styles.rb +37 -22
  71. data/lib/axlsx/stylesheet/table_style.rb +17 -16
  72. data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
  73. data/lib/axlsx/stylesheet/table_styles.rb +14 -11
  74. data/lib/axlsx/stylesheet/xf.rb +28 -26
  75. data/lib/axlsx/util/accessors.rb +64 -0
  76. data/lib/axlsx/util/constants.rb +127 -6
  77. data/lib/axlsx/util/options_parser.rb +15 -0
  78. data/lib/axlsx/util/serialized_attributes.rb +79 -0
  79. data/lib/axlsx/util/simple_typed_list.rb +50 -15
  80. data/lib/axlsx/util/validators.rb +51 -16
  81. data/lib/axlsx/version.rb +2 -2
  82. data/lib/axlsx/workbook/defined_name.rb +14 -59
  83. data/lib/axlsx/workbook/shared_strings_table.rb +13 -4
  84. data/lib/axlsx/workbook/workbook.rb +85 -6
  85. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  86. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
  87. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +246 -0
  88. data/lib/axlsx/workbook/worksheet/break.rb +37 -0
  89. data/lib/axlsx/workbook/worksheet/cell.rb +109 -107
  90. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +144 -0
  91. data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
  92. data/lib/axlsx/workbook/worksheet/cfvos.rb +15 -0
  93. data/lib/axlsx/workbook/worksheet/col.rb +43 -29
  94. data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
  95. data/lib/axlsx/workbook/worksheet/color_scale.rb +62 -28
  96. data/lib/axlsx/workbook/worksheet/comment.rb +28 -37
  97. data/lib/axlsx/workbook/worksheet/comments.rb +3 -3
  98. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
  99. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +31 -27
  100. data/lib/axlsx/workbook/worksheet/data_bar.rb +75 -41
  101. data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
  102. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +6 -5
  103. data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
  104. data/lib/axlsx/workbook/worksheet/header_footer.rb +54 -0
  105. data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
  106. data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
  107. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
  108. data/lib/axlsx/workbook/worksheet/page_setup.rb +152 -23
  109. data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
  110. data/lib/axlsx/workbook/worksheet/pivot_table.rb +273 -0
  111. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -0
  112. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -0
  113. data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
  114. data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
  115. data/lib/axlsx/workbook/worksheet/row.rb +59 -83
  116. data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
  117. data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
  118. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
  119. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +60 -0
  120. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +49 -4
  121. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
  122. data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
  123. data/lib/axlsx/workbook/worksheet/table.rb +25 -19
  124. data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
  125. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  126. data/lib/axlsx/workbook/worksheet/worksheet.rb +174 -35
  127. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -5
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +4 -10
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -0
  130. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
  131. data/lib/axlsx.rb +55 -5
  132. data/lib/schema/sml.xsd +4 -0
  133. data/test/axlsx.qcachegrind +2226 -0
  134. data/test/benchmark.rb +2 -3
  135. data/test/content_type/tc_default.rb +0 -11
  136. data/test/content_type/tc_override.rb +0 -13
  137. data/test/doc_props/tc_core.rb +7 -0
  138. data/test/drawing/tc_axes.rb +8 -0
  139. data/test/drawing/tc_axis.rb +15 -17
  140. data/test/drawing/tc_bar_3D_chart.rb +6 -0
  141. data/test/drawing/tc_cat_axis.rb +9 -9
  142. data/test/drawing/tc_chart.rb +20 -0
  143. data/test/drawing/tc_d_lbls.rb +14 -4
  144. data/test/drawing/tc_drawing.rb +0 -5
  145. data/test/drawing/tc_graphic_frame.rb +5 -3
  146. data/test/drawing/tc_hyperlink.rb +0 -4
  147. data/test/drawing/tc_line_chart.rb +39 -0
  148. data/test/drawing/tc_line_series.rb +8 -2
  149. data/test/drawing/tc_pic.rb +14 -3
  150. data/test/drawing/tc_ser_axis.rb +13 -12
  151. data/test/drawing/tc_two_cell_anchor.rb +3 -3
  152. data/test/drawing/tc_val_axis.rb +6 -6
  153. data/test/drawing/tc_vml_shape.rb +9 -3
  154. data/test/profile.rb +11 -21
  155. data/test/rels/tc_relationship.rb +32 -9
  156. data/test/rels/tc_relationships.rb +12 -1
  157. data/test/stylesheet/tc_color.rb +6 -0
  158. data/test/stylesheet/tc_styles.rb +15 -2
  159. data/test/tc_axlsx.rb +35 -2
  160. data/test/tc_helper.rb +7 -1
  161. data/test/tc_package.rb +44 -5
  162. data/test/util/tc_serialized_attributes.rb +19 -0
  163. data/test/util/tc_validators.rb +26 -1
  164. data/test/workbook/tc_defined_name.rb +2 -2
  165. data/test/workbook/tc_shared_strings_table.rb +6 -0
  166. data/test/workbook/tc_workbook.rb +38 -1
  167. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  168. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  169. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  170. data/test/workbook/worksheet/tc_break.rb +49 -0
  171. data/test/workbook/worksheet/tc_cell.rb +40 -6
  172. data/test/workbook/worksheet/tc_col.rb +11 -1
  173. data/test/workbook/worksheet/tc_color_scale.rb +31 -2
  174. data/test/workbook/worksheet/tc_comment.rb +21 -6
  175. data/test/workbook/worksheet/tc_comments.rb +2 -2
  176. data/test/workbook/worksheet/tc_conditional_formatting.rb +7 -0
  177. data/test/workbook/worksheet/tc_data_bar.rb +7 -0
  178. data/test/workbook/worksheet/tc_date_time_converter.rb +3 -11
  179. data/test/workbook/worksheet/tc_header_footer.rb +151 -0
  180. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  181. data/test/workbook/worksheet/tc_page_setup.rb +6 -1
  182. data/test/workbook/worksheet/tc_pane.rb +5 -45
  183. data/test/workbook/worksheet/tc_pivot_table.rb +120 -0
  184. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +54 -0
  185. data/test/workbook/worksheet/tc_row.rb +4 -4
  186. data/test/workbook/worksheet/tc_selection.rb +9 -48
  187. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  188. data/test/workbook/worksheet/tc_sheet_format_pr.rb +88 -0
  189. data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
  190. data/test/workbook/worksheet/tc_sheet_view.rb +39 -39
  191. data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +8 -3
  192. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  193. data/test/workbook/worksheet/tc_worksheet.rb +131 -16
  194. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -0
  195. metadata +97 -64
  196. data/examples/example.xlsx +0 -0
  197. data/examples/example_streamed.xlsx +0 -0
  198. data/examples/extractive.pdf +0 -0
  199. data/examples/image1.gif +0 -0
  200. data/examples/image1.jpg +0 -0
  201. data/examples/image1.png +0 -0
  202. data/examples/no-use_autowidth.xlsx +0 -0
  203. data/examples/sample.png +0 -0
  204. data/examples/scraping_html.rb +0 -91
  205. data/examples/shared_strings_example.xlsx +0 -0
  206. data/examples/sheet_view.rb +0 -34
  207. data/examples/two_cell_anchor_image.rb +0 -11
  208. data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
@@ -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,39 +7,45 @@ 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]
13
- attr_reader :scatterStyle
15
+ attr_reader :scatter_style
16
+ alias :scatterStyle :scatter_style
14
17
 
15
18
  # the x value axis
16
19
  # @return [ValAxis]
17
- attr_reader :xValAxis
20
+ def x_val_axis
21
+ axes[:x_val_axis]
22
+ end
23
+ alias :xValAxis :x_val_axis
18
24
 
19
25
  # the y value axis
20
26
  # @return [ValAxis]
21
- attr_reader :yValAxis
27
+ def y_val_axis
28
+ axes[:x_val_axis]
29
+ end
30
+ alias :yValAxis :y_val_axis
22
31
 
23
32
  # Creates a new scatter chart
24
33
  def initialize(frame, options={})
25
- @scatterStyle = :lineMarker
26
- @xValAxId = rand(8 ** 8)
27
- @yValAxId = rand(8 ** 8)
28
- @xValAxis = ValAxis.new(@xValAxId, @yValAxId)
29
- @yValAxis = ValAxis.new(@yValAxId, @xValAxId)
30
- super(frame, options)
34
+ @vary_colors = 0
35
+ @scatter_style = :lineMarker
36
+
37
+ super(frame, options)
31
38
  @series_type = ScatterSeries
32
39
  @d_lbls = nil
33
- options.each do |o|
34
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
35
- end
40
+ parse_options options
36
41
  end
37
42
 
38
43
  # see #scatterStyle
39
- def scatterStyle=(v)
44
+ def scatter_style=(v)
40
45
  Axlsx.validate_scatter_style(v)
41
- @scatterStyle = v
46
+ @scatter_style = v
42
47
  end
48
+ alias :scatterStyle= :scatter_style=
43
49
 
44
50
  # Serializes the object
45
51
  # @param [String] str
@@ -47,17 +53,22 @@ module Axlsx
47
53
  def to_xml_string(str = '')
48
54
  super(str) do |str_inner|
49
55
  str_inner << '<c:scatterChart>'
50
- str_inner << '<c:scatterStyle val="' << scatterStyle.to_s << '"/>'
51
- str_inner << '<c:varyColors val="1"/>'
56
+ str_inner << '<c:scatterStyle val="' << scatter_style.to_s << '"/>'
57
+ str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
52
58
  @series.each { |ser| ser.to_xml_string(str_inner) }
53
- d_lbls.to_xml_string(str) if @d_lbls
54
- str_inner << '<c:axId val="' << @xValAxId.to_s << '"/>'
55
- str_inner << '<c:axId val="' << @yValAxId.to_s << '"/>'
59
+ d_lbls.to_xml_string(str_inner) if @d_lbls
60
+ axes.to_xml_string(str_inner, :ids => true)
56
61
  str_inner << '</c:scatterChart>'
57
- @xValAxis.to_xml_string str_inner
58
- @yValAxis.to_xml_string str_inner
62
+ axes.to_xml_string(str_inner)
59
63
  end
60
64
  str
61
65
  end
66
+
67
+ # The axes for the scatter chart. ScatterChart has an x_val_axis and
68
+ # a y_val_axis
69
+ # @return [Axes]
70
+ def axes
71
+ @axes ||= Axes.new(:x_val_axis => ValAxis, :y_val_axis => ValAxis)
72
+ end
62
73
  end
63
74
  end
@@ -5,30 +5,29 @@ module Axlsx
5
5
 
6
6
  # The number of tick lables to skip between labels
7
7
  # @return [Integer]
8
- attr_reader :tickLblSkip
8
+ attr_reader :tick_lbl_skip
9
+ alias :tickLblSkip :tick_lbl_skip
9
10
 
10
11
  # The number of tickmarks to be skipped before the next one is rendered.
11
12
  # @return [Boolean]
12
- attr_reader :tickMarkSkip
13
+ attr_reader :tick_mark_skip
14
+ alias :tickMarkSkip :tick_mark_skip
13
15
 
14
16
  # Creates a new SerAxis object
15
- # @param [Integer] axId the id of this axis. Inherited
16
- # @param [Integer] crossAx the id of the perpendicular axis. Inherited
17
- # @option options [Symbol] axPos. Inherited
18
- # @option options [Symbol] tickLblPos. Inherited
19
- # @option options [Symbol] crosses. Inherited
20
- # @option options [Integer] tickLblSkip
21
- # @option options [Integer] tickMarkSkip
22
- def initialize(axId, crossAx, options={})
23
- @tickLblSkip, @tickMarkSkip = 1, 1
24
- super(axId, crossAx, options)
17
+ # @option options [Integer] tick_lbl_skip
18
+ # @option options [Integer] tick_mark_skip
19
+ def initialize(options={})
20
+ @tick_lbl_skip, @tick_mark_skip = 1, 1
21
+ super(options)
25
22
  end
26
23
 
27
24
  # @see tickLblSkip
28
- def tickLblSkip=(v) Axlsx::validate_unsigned_int(v); @tickLblSkip = v; end
25
+ def tick_lbl_skip=(v) Axlsx::validate_unsigned_int(v); @tick_lbl_skip = v; end
26
+ alias :tickLblSkip= :tick_lbl_skip=
29
27
 
30
28
  # @see tickMarkSkip
31
- def tickMarkSkip=(v) Axlsx::validate_unsigned_int(v); @tickMarkSkip = v; end
29
+ def tick_mark_skip=(v) Axlsx::validate_unsigned_int(v); @tick_mark_skip = v; end
30
+ alias :tickMarkSkip= :tick_mark_skip=
32
31
 
33
32
  # Serializes the object
34
33
  # @param [String] str
@@ -36,8 +35,8 @@ module Axlsx
36
35
  def to_xml_string(str = '')
37
36
  str << '<c:serAx>'
38
37
  super(str)
39
- str << '<c:tickLblSkip val="' << @tickLblSkip.to_s << '"/>' unless @tickLblSkip.nil?
40
- str << '<c:tickMarkSkip val="' << @tickMarkSkip.to_s << '"/>' unless @tickMarkSkip.nil?
38
+ str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>' unless @tick_lbl_skip.nil?
39
+ str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>' unless @tick_mark_skip.nil?
41
40
  str << '</c:serAx>'
42
41
  end
43
42
  end
@@ -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
@@ -5,6 +5,8 @@ module Axlsx
5
5
  # This class is extended for NumData to include the formatCode attribute required for numLit and numCache
6
6
  class StrData
7
7
 
8
+ include Axlsx::OptionsParser
9
+
8
10
  # creates a new StrVal object
9
11
  # @option options [Array] :data
10
12
  # @option options [String] :tag_name
@@ -12,9 +14,7 @@ module Axlsx
12
14
  @tag_prefix = :str
13
15
  @type = StrVal
14
16
  @pt = SimpleTypedList.new(@type)
15
- options.each do |o|
16
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
17
- end
17
+ parse_options options
18
18
  end
19
19
 
20
20
  # Creates the val objects for this data set. I am not overly confident this is going to play nicely with time and data types.
@@ -4,19 +4,20 @@ module Axlsx
4
4
  #This class specifies data for a particular data point.
5
5
  class StrVal
6
6
 
7
- # a string value.
8
- # @return [String]
9
- attr_reader :v
7
+ include Axlsx::OptionsParser
10
8
 
11
9
  # creates a new StrVal object
12
10
  # @option options [String] v
13
11
  def initialize(options={})
14
12
  @v = ""
15
13
  @idx = 0
16
- options.each do |o|
17
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
18
- end
14
+ parse_options options
19
15
  end
16
+
17
+ # a string value.
18
+ # @return [String]
19
+ attr_reader :v
20
+
20
21
  # @see v
21
22
  def v=(v)
22
23
  @v = v.to_s
@@ -27,7 +28,5 @@ module Axlsx
27
28
  Axlsx::validate_unsigned_int(idx)
28
29
  str << '<c:pt idx="' << idx.to_s << '"><c:v>' << v.to_s << '</c:v></c:pt>'
29
30
  end
30
-
31
31
  end
32
-
33
32
  end
@@ -5,6 +5,8 @@ module Axlsx
5
5
  # @see Worksheet#add_chart
6
6
  class TwoCellAnchor
7
7
 
8
+ include Axlsx::OptionsParser
9
+
8
10
  # A marker that defines the from cell anchor. The default from column and row are 0 and 0 respectively
9
11
  # @return [Marker]
10
12
  attr_reader :from
@@ -34,22 +36,23 @@ module Axlsx
34
36
  @drawing = drawing
35
37
  drawing.anchors << self
36
38
  @from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
39
+ parse_options options
37
40
  end
38
41
 
39
42
  # sets the col, row attributes for the from marker.
40
43
  # @note The recommended way to set the start position for graphical
41
44
  # objects is directly thru the object.
42
45
  # @see Chart#start_at
43
- def start_at(x, y)
44
- set_marker_coords(x, y, from)
46
+ def start_at(x, y=nil)
47
+ from.coord x, y
45
48
  end
46
49
 
47
50
  # sets the col, row attributes for the to marker
48
51
  # @note the recommended way to set the to position for graphical
49
52
  # objects is directly thru the object
50
53
  # @see Char#end_at
51
- def end_at(x, y)
52
- set_marker_coords(x, y, to)
54
+ def end_at(x, y=nil)
55
+ to.coord x, y
53
56
  end
54
57
 
55
58
  # Creates a graphic frame and chart object associated with this anchor
@@ -85,28 +88,5 @@ module Axlsx
85
88
  str << '<xdr:clientData/>'
86
89
  str << '</xdr:twoCellAnchor>'
87
90
  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
-
110
-
111
91
  end
112
92
  end
@@ -6,21 +6,22 @@ module Axlsx
6
6
  # This element specifies how the value axis crosses the category axis.
7
7
  # must be one of [:between, :midCat]
8
8
  # @return [Symbol]
9
- attr_reader :crossBetween
9
+ attr_reader :cross_between
10
+ alias :crossBetween :cross_between
10
11
 
11
12
  # Creates a new ValAxis object
12
- # @param [Integer] axId the id of this axis
13
- # @param [Integer] crossAx the id of the perpendicular axis
14
- # @option options [Symbol] axPos
15
- # @option options [Symbol] tickLblPos
16
- # @option options [Symbol] crosses
17
- # @option options [Symbol] crossesBetween
18
- def initialize(axId, crossAx, options={})
19
- self.crossBetween = :between
20
- super(axId, crossAx, options)
13
+ # @option options [Symbol] crosses_between
14
+ def initialize(options={})
15
+ self.cross_between = :between
16
+ super(options)
21
17
  end
22
- # @see crossBetween
23
- def crossBetween=(v) RestrictionValidator.validate "ValAxis.crossBetween", [:between, :midCat], v; @crossBetween = v; end
18
+
19
+ # @see cross_between
20
+ def cross_between=(v)
21
+ RestrictionValidator.validate "ValAxis.cross_between", [:between, :midCat], v
22
+ @cross_between = v
23
+ end
24
+ alias :crossBetween= :cross_between=
24
25
 
25
26
  # Serializes the object
26
27
  # @param [String] str
@@ -28,7 +29,7 @@ module Axlsx
28
29
  def to_xml_string(str = '')
29
30
  str << '<c:valAx>'
30
31
  super(str)
31
- str << '<c:crossBetween val="' << @crossBetween.to_s << '"/>'
32
+ str << '<c:crossBetween val="' << @cross_between.to_s << '"/>'
32
33
  str << '</c:valAx>'
33
34
  end
34
35
 
@@ -3,6 +3,20 @@ module Axlsx
3
3
  # 3D attributes for a chart.
4
4
  class View3D
5
5
 
6
+ include Axlsx::OptionsParser
7
+
8
+ # Creates a new View3D for charts
9
+ # @option options [Integer] rot_x
10
+ # @option options [String] h_percent
11
+ # @option options [Integer] rot_y
12
+ # @option options [String] depth_percent
13
+ # @option options [Boolean] r_ang_ax
14
+ # @option options [Integer] perspective
15
+ def initialize(options={})
16
+ @rot_x, @h_percent, @rot_y, @depth_percent, @r_ang_ax, @perspective = nil, nil, nil, nil, nil, nil
17
+ parse_options options
18
+ end
19
+
6
20
  # Validation for hPercent
7
21
  H_PERCENT_REGEX = /0*(([5-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)/
8
22
 
@@ -14,8 +28,8 @@ module Axlsx
14
28
  # @return [Integer]
15
29
  attr_reader :rot_x
16
30
  alias :rotX :rot_x
17
-
18
- # height of chart as % of chart
31
+
32
+ # height of chart as % of chart width
19
33
  # must be between 5% and 500%
20
34
  # @return [String]
21
35
  attr_reader :h_percent
@@ -26,7 +40,7 @@ module Axlsx
26
40
  # @return [Integer]
27
41
  attr_reader :rot_y
28
42
  alias :rotY :rot_y
29
-
43
+
30
44
  # depth or chart as % of chart width
31
45
  # must be between 20% and 2000%
32
46
  # @return [String]
@@ -42,60 +56,60 @@ module Axlsx
42
56
  # @return [Integer]
43
57
  attr_reader :perspective
44
58
 
45
- # Creates a new View3D for charts
46
- # @option options [Integer] rot_x
47
- # @option options [String] h_percent
48
- # @option options [Integer] rot_y
49
- # @option options [String] depth_percent
50
- # @option options [Boolean] r_ang_ax
51
- # @option options [Integer] perspective
52
- def initialize(options={})
53
- @rot_x, @h_percent, @rot_y, @depth_percent, @r_ang_ax, @perspective = nil, nil, nil, nil, nil, nil
54
- options.each do |o|
55
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
56
- end
57
- end
58
-
59
59
  # @see rot_x
60
- def rot_x=(v) DataTypeValidator.validate "#{self.class}.rot_x", [Integer, Fixnum], v, lambda {|arg| arg >= -90 && arg <= 90 }; @rot_x = v; end
60
+ def rot_x=(v)
61
+ RangeValidator.validate "View3D.rot_x", -90, 90, v
62
+ @rot_x = v
63
+ end
61
64
  alias :rotX= :rot_x=
62
65
 
63
- # @see h_percent
64
- def h_percent=(v)
65
- RegexValidator.validate "#{self.class}.h_percent", H_PERCENT_REGEX, v
66
- @h_percent = v
67
- end
66
+ # @see h_percent
67
+ def h_percent=(v)
68
+ RegexValidator.validate "#{self.class}.h_percent", H_PERCENT_REGEX, v
69
+ @h_percent = v
70
+ end
68
71
  alias :hPercent= :h_percent=
69
72
 
70
- # @see rot_y
71
- def rot_y=(v) DataTypeValidator.validate "#{self.class}.rot_y", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 360 }; @rot_y = v; end
73
+ # @see rot_y
74
+ def rot_y=(v)
75
+ RangeValidator.validate "View3D.rot_y", 0, 360, v
76
+ @rot_y = v
77
+ end
72
78
  alias :rotY= :rot_y=
73
79
 
74
- # @see depth_percent
75
- def depth_percent=(v) RegexValidator.validate "#{self.class}.depth_percent", DEPTH_PERCENT_REGEX, v; @depth_percent = v; end
80
+ # @see depth_percent
81
+ def depth_percent=(v) RegexValidator.validate "#{self.class}.depth_percent", DEPTH_PERCENT_REGEX, v; @depth_percent = v; end
76
82
  alias :depthPercent= :depth_percent=
77
83
 
78
- # @see r_ang_ax
79
- def r_ang_ax=(v) Axlsx::validate_boolean(v); @r_ang_ax = v; end
84
+ # @see r_ang_ax
85
+ def r_ang_ax=(v) Axlsx::validate_boolean(v); @r_ang_ax = v; end
80
86
  alias :rAngAx= :r_ang_ax=
81
-
82
- # @see perspective
83
- def perspective=(v) DataTypeValidator.validate "#{self.class}.perspective", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end
84
87
 
88
+ # @see perspective
89
+ def perspective=(v)
90
+ RangeValidator.validate "View3D.perspective", 0, 240, v
91
+ @perspective = v
92
+ end
93
+
94
+ # DataTypeValidator.validate "#{self.class}.perspective", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end
85
95
 
86
96
  # Serializes the object
87
97
  # @param [String] str
88
98
  # @return [String]
89
99
  def to_xml_string(str = '')
90
100
  str << '<c:view3D>'
91
- str << '<c:rotX val="' << @rot_x.to_s << '"/>' unless @rot_x.nil?
92
- str << '<c:hPercent val="' << @h_percent.to_s << '"/>' unless @h_percent.nil?
93
- str << '<c:rotY val="' << @rot_y.to_s << '"/>' unless @rot_y.nil?
94
- str << '<c:depthPercent val="' << @depth_percent.to_s << '"/>' unless @depth_percent.nil?
95
- str << '<c:rAngAx val="' << @r_ang_ax.to_s << '"/>' unless @r_ang_ax.nil?
96
- str << '<c:perspective val="' << @perspective.to_s << '"/>' unless @perspective.nil?
101
+ %w(rot_x h_percent rot_y depth_percent r_ang_ax perspective).each do |key|
102
+ str << element_for_attribute(key, 'c')
103
+ end
97
104
  str << '</c:view3D>'
98
105
  end
99
106
 
107
+ private
108
+ # Note: move this to Axlsx module if we find the smae pattern elsewhere.
109
+ def element_for_attribute(name, namespace='')
110
+ val = instance_values[name]
111
+ return "" if val == nil
112
+ "<%s:%s val='%s'/>" % [namespace, Axlsx::camel(name, false), val]
113
+ end
100
114
  end
101
115
  end
@@ -3,96 +3,36 @@ module Axlsx
3
3
  # A VmlShape is used to position and render a comment.
4
4
  class VmlShape
5
5
 
6
- # The row anchor position for this shape determined by the comment's ref value
7
- # @return [Integer]
8
- attr_reader :row
9
-
10
- # The column anchor position for this shape determined by the comment's ref value
11
- # @return [Integer]
12
- attr_reader :column
13
-
14
- # The left column for this shape
15
- # @return [Integer]
16
- attr_reader :left_column
17
-
18
- # The left offset for this shape
19
- # @return [Integer]
20
- attr_reader :left_offset
21
-
22
- # The top row for this shape
23
- # @return [Integer]
24
- attr_reader :top_row
25
-
26
- # The top offset for this shape
27
- # @return [Integer]
28
- attr_reader :top_offset
29
-
30
- # The right column for this shape
31
- # @return [Integer]
32
- attr_reader :right_column
33
-
34
- # The right offset for this shape
35
- # @return [Integer]
36
- attr_reader :right_offset
37
-
38
- # The botttom row for this shape
39
- # @return [Integer]
40
- attr_reader :bottom_row
41
-
42
- # The bottom offset for this shape
43
- # @return [Integer]
44
- attr_reader :bottom_offset
6
+ include Axlsx::OptionsParser
7
+ include Axlsx::Accessors
45
8
 
46
9
  # Creates a new VmlShape
47
- # @option options [Integer|String] left_column
48
- # @option options [Integer|String] left_offset
49
- # @option options [Integer|String] top_row
50
- # @option options [Integer|String] top_offset
51
- # @option options [Integer|String] right_column
52
- # @option options [Integer|String] right_offset
53
- # @option options [Integer|String] bottom_row
54
- # @option options [Integer|String] bottom_offset
10
+ # @option options [Integer] row
11
+ # @option options [Integer] column
12
+ # @option options [Integer] left_column
13
+ # @option options [Integer] left_offset
14
+ # @option options [Integer] top_row
15
+ # @option options [Integer] top_offset
16
+ # @option options [Integer] right_column
17
+ # @option options [Integer] right_offset
18
+ # @option options [Integer] bottom_row
19
+ # @option options [Integer] bottom_offset
55
20
  def initialize(options={})
56
21
  @row = @column = @left_column = @top_row = @right_column = @bottom_row = 0
57
22
  @left_offset = 15
58
23
  @top_offset = 2
59
24
  @right_offset = 50
60
25
  @bottom_offset = 5
26
+ @visible = true
61
27
  @id = (0...8).map{65.+(rand(25)).chr}.join
62
- options.each do |o|
63
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
64
- end
28
+ parse_options options
65
29
  yield self if block_given?
66
30
  end
67
31
 
68
- # @see column
69
- def column=(v); Axlsx::validate_integerish(v); @column = v.to_i end
70
-
71
- # @see row
72
- def row=(v); Axlsx::validate_integerish(v); @row = v.to_i end
73
- # @see left_column
74
- def left_column=(v); Axlsx::validate_integerish(v); @left_column = v.to_i end
75
-
76
- # @see left_offset
77
- def left_offset=(v); Axlsx::validate_integerish(v); @left_offset = v.to_i end
78
-
79
- # @see top_row
80
- def top_row=(v); Axlsx::validate_integerish(v); @top_row = v.to_i end
81
-
82
- # @see top_offset
83
- def top_offset=(v); Axlsx::validate_integerish(v); @top_offset = v.to_i end
84
-
85
- # @see right_column
86
- def right_column=(v); Axlsx::validate_integerish(v); @right_column = v.to_i end
87
-
88
- # @see right_offset
89
- def right_offset=(v); Axlsx::validate_integerish(v); @right_offset = v.to_i end
90
-
91
- # @see bottom_row
92
- def bottom_row=(v); Axlsx::validate_integerish(v); @bottom_row = v.to_i end
32
+ unsigned_int_attr_accessor :row, :column, :left_column, :left_offset, :top_row, :top_offset,
33
+ :right_column, :right_offset, :bottom_row, :bottom_offset
93
34
 
94
- # @see bottom_offset
95
- def bottom_offset=(v); Axlsx::validate_integerish(v); @bottom_offset = v.to_i end
35
+ boolean_attr_accessor :visible
96
36
 
97
37
  # serialize the shape to a string
98
38
  # @param [String] str
@@ -100,7 +40,8 @@ module Axlsx
100
40
  def to_xml_string(str ='')
101
41
  str << <<SHAME_ON_YOU
102
42
 
103
- <v:shape id="#{@id}" type="#_x0000_t202" fillcolor="#ffffa1 [80]" o:insetmode="auto">
43
+ <v:shape id="#{@id}" type="#_x0000_t202" fillcolor="#ffffa1 [80]" o:insetmode="auto"
44
+ style="visibility:#{@visible ? 'visible' : 'hidden'}">
104
45
  <v:fill color2="#ffffa1 [80]"/>
105
46
  <v:shadow on="t" obscured="t"/>
106
47
  <v:path o:connecttype="none"/>
@@ -115,7 +56,7 @@ str << <<SHAME_ON_YOU
115
56
  <x:AutoFill>False</x:AutoFill>
116
57
  <x:Row>#{row}</x:Row>
117
58
  <x:Column>#{column}</x:Column>
118
- <x:Visible/>
59
+ #{@visible ? '<x:Visible/>' : ''}
119
60
  </x:ClientData>
120
61
  </v:shape>
121
62
  SHAME_ON_YOU