axlsx 1.1.0 → 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 (214) hide show
  1. data/.yardopts +5 -2
  2. data/CHANGELOG.md +78 -0
  3. data/LICENSE +1 -1
  4. data/README.md +132 -331
  5. data/Rakefile +17 -5
  6. data/examples/basic_charts.rb +54 -0
  7. data/examples/chart_colors.rb +88 -0
  8. data/examples/conditional_formatting/example_conditional_formatting.rb +72 -0
  9. data/examples/conditional_formatting/getting_barred.rb +37 -0
  10. data/examples/conditional_formatting/hitting_the_high_notes.rb +37 -0
  11. data/examples/conditional_formatting/scaled_colors.rb +39 -0
  12. data/examples/conditional_formatting/stop_and_go.rb +37 -0
  13. data/examples/data_validation.rb +50 -0
  14. data/examples/example.rb +300 -152
  15. data/examples/example.xlsx +0 -0
  16. data/examples/example_streamed.xlsx +0 -0
  17. data/examples/extractive.pdf +0 -0
  18. data/examples/extractive.rb +45 -0
  19. data/examples/no-use_autowidth.xlsx +0 -0
  20. data/examples/sample.png +0 -0
  21. data/examples/scraping_html.rb +91 -0
  22. data/examples/shared_strings_example.xlsx +0 -0
  23. data/examples/sheet_protection.rb +10 -0
  24. data/examples/sheet_view.rb +34 -0
  25. data/examples/skydrive/real_example.rb +63 -0
  26. data/examples/two_cell_anchor_image.rb +11 -0
  27. data/lib/axlsx/content_type/content_type.rb +2 -0
  28. data/lib/axlsx/content_type/default.rb +30 -15
  29. data/lib/axlsx/content_type/override.rb +29 -14
  30. data/lib/axlsx/doc_props/app.rb +161 -104
  31. data/lib/axlsx/doc_props/core.rb +9 -5
  32. data/lib/axlsx/drawing/ax_data_source.rb +26 -0
  33. data/lib/axlsx/drawing/axis.rb +106 -35
  34. data/lib/axlsx/drawing/bar_3D_chart.rb +49 -45
  35. data/lib/axlsx/drawing/bar_series.rb +25 -7
  36. data/lib/axlsx/drawing/cat_axis.rb +50 -22
  37. data/lib/axlsx/drawing/chart.rb +69 -56
  38. data/lib/axlsx/drawing/d_lbls.rb +100 -0
  39. data/lib/axlsx/drawing/drawing.rb +28 -12
  40. data/lib/axlsx/drawing/graphic_frame.rb +2 -1
  41. data/lib/axlsx/drawing/line_3D_chart.rb +3 -10
  42. data/lib/axlsx/drawing/line_series.rb +20 -4
  43. data/lib/axlsx/drawing/num_data.rb +52 -0
  44. data/lib/axlsx/drawing/num_data_source.rb +61 -0
  45. data/lib/axlsx/drawing/num_val.rb +32 -0
  46. data/lib/axlsx/drawing/pic.rb +44 -4
  47. data/lib/axlsx/drawing/pie_3D_chart.rb +10 -7
  48. data/lib/axlsx/drawing/pie_series.rb +18 -4
  49. data/lib/axlsx/drawing/scatter_chart.rb +12 -18
  50. data/lib/axlsx/drawing/scatter_series.rb +28 -2
  51. data/lib/axlsx/drawing/ser_axis.rb +1 -1
  52. data/lib/axlsx/drawing/series.rb +1 -1
  53. data/lib/axlsx/drawing/str_data.rb +42 -0
  54. data/lib/axlsx/drawing/str_val.rb +33 -0
  55. data/lib/axlsx/drawing/title.rb +21 -9
  56. data/lib/axlsx/drawing/two_cell_anchor.rb +46 -9
  57. data/lib/axlsx/drawing/view_3D.rb +44 -31
  58. data/lib/axlsx/drawing/vml_drawing.rb +42 -0
  59. data/lib/axlsx/drawing/vml_shape.rb +125 -0
  60. data/lib/axlsx/package.rb +44 -16
  61. data/lib/axlsx/rels/relationship.rb +3 -3
  62. data/lib/axlsx/rels/relationships.rb +1 -11
  63. data/lib/axlsx/stylesheet/color.rb +0 -1
  64. data/lib/axlsx/stylesheet/dxf.rb +79 -0
  65. data/lib/axlsx/stylesheet/font.rb +2 -1
  66. data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
  67. data/lib/axlsx/stylesheet/styles.rb +143 -50
  68. data/lib/axlsx/stylesheet/table_style.rb +3 -3
  69. data/lib/axlsx/stylesheet/xf.rb +2 -0
  70. data/lib/axlsx/util/constants.rb +36 -0
  71. data/lib/axlsx/util/simple_typed_list.rb +15 -21
  72. data/lib/axlsx/util/validators.rb +122 -5
  73. data/lib/axlsx/version.rb +2 -7
  74. data/lib/axlsx/workbook/defined_name.rb +174 -0
  75. data/lib/axlsx/workbook/defined_names.rb +21 -0
  76. data/lib/axlsx/workbook/shared_strings_table.rb +12 -13
  77. data/lib/axlsx/workbook/workbook.rb +71 -13
  78. data/lib/axlsx/workbook/worksheet/auto_filter.rb +34 -0
  79. data/lib/axlsx/workbook/worksheet/cell.rb +45 -36
  80. data/lib/axlsx/workbook/worksheet/cfvo.rb +62 -0
  81. data/lib/axlsx/workbook/worksheet/col.rb +17 -1
  82. data/lib/axlsx/workbook/worksheet/color_scale.rb +76 -0
  83. data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
  84. data/lib/axlsx/workbook/worksheet/comment.rb +101 -0
  85. data/lib/axlsx/workbook/worksheet/comments.rb +85 -0
  86. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +82 -0
  87. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +216 -0
  88. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
  89. data/lib/axlsx/workbook/worksheet/data_bar.rb +97 -0
  90. data/lib/axlsx/workbook/worksheet/data_validation.rb +245 -0
  91. data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
  92. data/lib/axlsx/workbook/worksheet/dimension.rb +65 -0
  93. data/lib/axlsx/workbook/worksheet/icon_set.rb +83 -0
  94. data/lib/axlsx/workbook/worksheet/merged_cells.rb +35 -0
  95. data/lib/axlsx/workbook/worksheet/page_setup.rb +113 -0
  96. data/lib/axlsx/workbook/worksheet/pane.rb +144 -0
  97. data/lib/axlsx/workbook/worksheet/print_options.rb +63 -0
  98. data/lib/axlsx/workbook/worksheet/protected_range.rb +46 -0
  99. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
  100. data/lib/axlsx/workbook/worksheet/row.rb +69 -12
  101. data/lib/axlsx/workbook/worksheet/selection.rb +111 -0
  102. data/lib/axlsx/workbook/worksheet/sheet_data.rb +25 -0
  103. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +24 -0
  104. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +224 -0
  105. data/lib/axlsx/workbook/worksheet/sheet_view.rb +379 -0
  106. data/lib/axlsx/workbook/worksheet/table.rb +3 -3
  107. data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
  108. data/lib/axlsx/workbook/worksheet/worksheet.rb +379 -233
  109. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +57 -0
  110. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +64 -0
  111. data/lib/axlsx.rb +31 -16
  112. data/test/benchmark.rb +30 -38
  113. data/test/content_type/tc_content_type.rb +1 -6
  114. data/test/doc_props/tc_app.rb +31 -1
  115. data/test/doc_props/tc_core.rb +3 -1
  116. data/test/drawing/tc_axis.rb +46 -3
  117. data/test/drawing/tc_bar_3D_chart.rb +12 -12
  118. data/test/drawing/tc_bar_series.rb +17 -13
  119. data/test/drawing/tc_cat_axis.rb +3 -3
  120. data/test/drawing/tc_cat_axis_data.rb +23 -13
  121. data/test/drawing/tc_chart.rb +29 -11
  122. data/test/drawing/tc_d_lbls.rb +47 -0
  123. data/test/drawing/tc_data_source.rb +17 -0
  124. data/test/drawing/tc_drawing.rb +11 -5
  125. data/test/drawing/tc_hyperlink.rb +4 -5
  126. data/test/drawing/tc_line_series.rb +9 -11
  127. data/test/drawing/tc_named_axis_data.rb +27 -0
  128. data/test/drawing/tc_num_data.rb +31 -0
  129. data/test/drawing/tc_num_val.rb +29 -0
  130. data/test/drawing/tc_pic.rb +22 -2
  131. data/test/drawing/tc_pie_3D_chart.rb +4 -8
  132. data/test/drawing/tc_pie_series.rb +11 -13
  133. data/test/drawing/tc_scatter_chart.rb +6 -1
  134. data/test/drawing/tc_scatter_series.rb +6 -5
  135. data/test/drawing/tc_series.rb +1 -1
  136. data/test/drawing/tc_str_data.rb +18 -0
  137. data/test/drawing/tc_str_val.rb +21 -0
  138. data/test/drawing/tc_title.rb +16 -0
  139. data/test/drawing/tc_two_cell_anchor.rb +2 -3
  140. data/test/drawing/tc_view_3D.rb +18 -18
  141. data/test/drawing/tc_vml_drawing.rb +25 -0
  142. data/test/drawing/tc_vml_shape.rb +100 -0
  143. data/test/profile.rb +2 -1
  144. data/test/rels/tc_relationship.rb +1 -0
  145. data/test/stylesheet/tc_dxf.rb +81 -0
  146. data/test/stylesheet/tc_gradient_fill.rb +8 -0
  147. data/test/stylesheet/tc_pattern_fill.rb +7 -1
  148. data/test/stylesheet/tc_styles.rb +163 -3
  149. data/test/stylesheet/tc_table_style.rb +8 -0
  150. data/test/stylesheet/tc_table_style_element.rb +10 -1
  151. data/test/tc_helper.rb +1 -0
  152. data/test/tc_package.rb +93 -17
  153. data/test/util/tc_simple_typed_list.rb +13 -0
  154. data/test/util/tc_validators.rb +95 -9
  155. data/test/workbook/tc_defined_name.rb +41 -0
  156. data/test/workbook/tc_workbook.rb +5 -3
  157. data/test/workbook/worksheet/table/tc_table.rb +3 -11
  158. data/test/workbook/worksheet/tc_cell.rb +52 -18
  159. data/test/workbook/worksheet/tc_cfvo.rb +31 -0
  160. data/test/workbook/worksheet/tc_col.rb +9 -0
  161. data/test/workbook/worksheet/tc_color_scale.rb +29 -0
  162. data/test/workbook/worksheet/tc_comment.rb +57 -0
  163. data/test/workbook/worksheet/tc_comments.rb +57 -0
  164. data/test/workbook/worksheet/tc_conditional_formatting.rb +217 -0
  165. data/test/workbook/worksheet/tc_data_bar.rb +39 -0
  166. data/test/workbook/worksheet/tc_data_validation.rb +265 -0
  167. data/test/workbook/worksheet/tc_date_time_converter.rb +11 -5
  168. data/test/workbook/worksheet/tc_icon_set.rb +45 -0
  169. data/test/workbook/worksheet/tc_page_setup.rb +138 -0
  170. data/test/workbook/worksheet/tc_pane.rb +94 -0
  171. data/test/workbook/worksheet/tc_print_options.rb +72 -0
  172. data/test/workbook/worksheet/tc_protected_range.rb +17 -0
  173. data/test/workbook/worksheet/tc_row.rb +44 -13
  174. data/test/workbook/worksheet/tc_selection.rb +94 -0
  175. data/test/workbook/worksheet/tc_sheet_protection.rb +117 -0
  176. data/test/workbook/worksheet/tc_sheet_view.rb +214 -0
  177. data/test/workbook/worksheet/tc_worksheet.rb +147 -50
  178. metadata +216 -148
  179. data/examples/example.csv +0 -1000
  180. data/examples/example.rb~ +0 -112
  181. data/lib/axlsx/drawing/cat_axis_data.rb +0 -34
  182. data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
  183. data/lib/axlsx/drawing/hyperlink.rb~ +0 -64
  184. data/lib/axlsx/drawing/named_axis_data.rb +0 -36
  185. data/lib/axlsx/drawing/picture_locking.rb~ +0 -36
  186. data/lib/axlsx/drawing/val_axis_data.rb +0 -27
  187. data/lib/axlsx/stylesheet/#num_fmt.rb# +0 -69
  188. data/lib/axlsx/util/cbf.rb +0 -333
  189. data/lib/axlsx/util/cfb.rb~ +0 -201
  190. data/lib/axlsx/util/ms_off_crypto.rb +0 -189
  191. data/lib/axlsx/util/ms_off_crypto.rb~ +0 -3
  192. data/lib/axlsx/util/ms_offcrypto.rb~ +0 -0
  193. data/lib/axlsx/util/parser.rb~ +0 -6
  194. data/lib/axlsx/util/storage.rb~ +0 -0
  195. data/lib/axlsx/workbook/shared_strings_table.rb~ +0 -69
  196. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  197. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  198. data/lib/axlsx/workbook/worksheet/table.rb~ +0 -97
  199. data/lib/schema/dc.xsd~ +0 -118
  200. data/lib/schema/dcterms.xsd~ +0 -331
  201. data/lib/schema/opc-coreProperties.xsd~ +0 -50
  202. data/test/#benchmark.txt# +0 -7
  203. data/test/#tc_helper.rb# +0 -3
  204. data/test/benchmark.rb~ +0 -0
  205. data/test/benchmark.txt +0 -6
  206. data/test/benchmark.txt~ +0 -6
  207. data/test/drawing/tc_val_axis_data.rb +0 -17
  208. data/test/example.csv +0 -1000
  209. data/test/example.xlsx +0 -0
  210. data/test/example_streamed.xlsx +0 -0
  211. data/test/tc_axlsx.rb~ +0 -0
  212. data/test/tc_helper.rb~ +0 -3
  213. data/test/workbook/worksheet/table/tc_table.rb~ +0 -72
  214. data/test/workbook/worksheet/tc_col.rb~ +0 -10
@@ -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'
@@ -10,14 +11,18 @@ module Axlsx
10
11
 
11
12
  require 'axlsx/drawing/scaling.rb'
12
13
  require 'axlsx/drawing/axis.rb'
14
+
15
+ require 'axlsx/drawing/str_val.rb'
16
+ require 'axlsx/drawing/num_val.rb'
17
+ require 'axlsx/drawing/str_data.rb'
18
+ require 'axlsx/drawing/num_data.rb'
19
+ require 'axlsx/drawing/num_data_source.rb'
20
+ require 'axlsx/drawing/ax_data_source.rb'
21
+
13
22
  require 'axlsx/drawing/ser_axis.rb'
14
23
  require 'axlsx/drawing/cat_axis.rb'
15
24
  require 'axlsx/drawing/val_axis.rb'
16
25
 
17
- require 'axlsx/drawing/cat_axis_data.rb'
18
- require 'axlsx/drawing/val_axis_data.rb'
19
- require 'axlsx/drawing/named_axis_data.rb'
20
-
21
26
  require 'axlsx/drawing/marker.rb'
22
27
 
23
28
  require 'axlsx/drawing/one_cell_anchor.rb'
@@ -35,12 +40,16 @@ module Axlsx
35
40
  require 'axlsx/drawing/pic.rb'
36
41
  require 'axlsx/drawing/hyperlink.rb'
37
42
 
38
- # A Drawing is a canvas for charts. Each worksheet has a single drawing that manages anchors.
39
- # The anchors reference the charts via graphical frames. This is not a trivial relationship so please do follow the advice in the note.
40
- # @note The recommended way to manage drawings is to use the Worksheet.add_chart method.
43
+ require 'axlsx/drawing/vml_drawing.rb'
44
+ require 'axlsx/drawing/vml_shape.rb'
45
+
46
+ # A Drawing is a canvas for charts and images. Each worksheet has a single drawing that manages anchors.
47
+ # The anchors reference the charts or images via graphical frames. This is not a trivial relationship so please do follow the advice in the note.
48
+ # @note The recommended way to manage drawings is to use the Worksheet.add_chart and Worksheet.add_image methods.
41
49
  # @see Worksheet#add_chart
50
+ # @see Worksheet#add_image
42
51
  # @see Chart
43
- # see README for an example of how to create a chart.
52
+ # see examples/example.rb for an example of how to create a chart.
44
53
  class Drawing
45
54
 
46
55
  # The worksheet that owns the drawing
@@ -61,11 +70,17 @@ module Axlsx
61
70
  @anchors = SimpleTypedList.new [TwoCellAnchor, OneCellAnchor]
62
71
  end
63
72
 
64
- # Adds an image to the chart
73
+
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.
65
75
  # @note The recommended way to manage images is to use Worksheet.add_image. Please refer to that method for documentation.
66
76
  # @see Worksheet#add_image
77
+ # @return [Pic]
67
78
  def add_image(options={})
68
- OneCellAnchor.new(self, options)
79
+ if options[:end_at]
80
+ TwoCellAnchor.new(self, options).add_pic(options)
81
+ else
82
+ OneCellAnchor.new(self, options)
83
+ end
69
84
  @anchors.last.object
70
85
  end
71
86
 
@@ -142,8 +157,9 @@ module Axlsx
142
157
  # @param [String] str
143
158
  # @return [String]
144
159
  def to_xml_string(str = '')
145
- str << '<?xml version="1.0" encoding="UTF-8"?>'
146
- str << '<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '" xmlns:c="' << XML_NS_C << '">'
160
+ str << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
161
+ str << '<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '">'
162
+
147
163
  anchors.each { |anchor| anchor.to_xml_string(str) }
148
164
  str << '</xdr:wsDr>'
149
165
  end
@@ -32,9 +32,10 @@ module Axlsx
32
32
  # @param [String] str
33
33
  # @return [String]
34
34
  def to_xml_string(str = '')
35
+ # macro attribute should be optional!
35
36
  str << '<xdr:graphicFrame>'
36
37
  str << '<xdr:nvGraphicFramePr>'
37
- str << '<xdr:cNvPr id="2" name="' << chart.title.text << '"/>'
38
+ str << '<xdr:cNvPr id="' << @anchor.drawing.index.to_s << '" name="' << 'item_' << @anchor.drawing.index.to_s << '"/>'
38
39
  str << '<xdr:cNvGraphicFramePr/>'
39
40
  str << '</xdr:nvGraphicFramePr>'
40
41
  str << '<xdr:xfrm>'
@@ -70,7 +70,8 @@ module Axlsx
70
70
  @serAxis = SerAxis.new(@serAxId, @valAxId)
71
71
  super(frame, options)
72
72
  @series_type = LineSeries
73
- @view3D = View3D.new({:perspective=>30}.merge(options))
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
@@ -14,6 +14,11 @@ module Axlsx
14
14
  # @return [CatAxisData]
15
15
  attr_reader :labels
16
16
 
17
+ # The fill color for this series.
18
+ # Red, green, and blue is expressed as sequence of hex digits, RRGGBB. A perceptual gamma of 2.2 is used.
19
+ # @return [String]
20
+ attr_reader :color
21
+
17
22
  # Creates a new series
18
23
  # @option options [Array, SimpleTypedList] data
19
24
  # @option options [Array, SimpleTypedList] labels
@@ -21,8 +26,13 @@ module Axlsx
21
26
  def initialize(chart, options={})
22
27
  @labels, @data = nil, nil
23
28
  super(chart, options)
24
- @labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
25
- @data = ValAxisData.new(options[:data]) unless options[:data].nil?
29
+ @labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
30
+ @data = NumDataSource.new(options) unless options[:data].nil?
31
+ end
32
+
33
+ # @see color
34
+ def color=(v)
35
+ @color = v
26
36
  end
27
37
 
28
38
  # Serializes the object
@@ -30,6 +40,12 @@ module Axlsx
30
40
  # @return [String]
31
41
  def to_xml_string(str = '')
32
42
  super(str) do
43
+ if color
44
+ str << '<c:spPr><a:solidFill>'
45
+ str << '<a:srgbClr val="' << color << '"/>'
46
+ str << '</a:solidFill></c:spPr>'
47
+ end
48
+
33
49
  @labels.to_xml_string(str) unless @labels.nil?
34
50
  @data.to_xml_string(str) unless @data.nil?
35
51
  end
@@ -38,10 +54,10 @@ module Axlsx
38
54
  private
39
55
 
40
56
  # assigns the data for this series
41
- def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
57
+ def data=(v) DataTypeValidator.validate "Series.data", [NumDataSource], v; @data = v; end
42
58
 
43
59
  # assigns the labels for this series
44
- def labels=(v) DataTypeValidator.validate "Series.labels", [SimpleTypedList], v; @labels = v; end
60
+ def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
45
61
 
46
62
  end
47
63
  end
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Axlsx
3
+
4
+ #This class specifies data for a particular data point. It is used for both numCache and numLit object
5
+ class NumData
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
10
+
11
+ # creates a new NumVal object
12
+ # @option options [String] formatCode
13
+ # @option options [Array] :data
14
+ # @see StrData
15
+ def initialize(options={})
16
+ @format_code = "General"
17
+ @pt = SimpleTypedList.new NumVal
18
+ options.each do |o|
19
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
20
+ end
21
+ end
22
+
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
+ # @param [Array] values An array of cells or values.
25
+ def data=(values=[])
26
+ @tag_name = values.first.is_a?(Cell) ? :numCache : :numLit
27
+ values.each do |value|
28
+ value = value.is_formula? ? 0 : value.value if value.is_a?(Cell)
29
+ @pt << NumVal.new(:v => value)
30
+ end
31
+ end
32
+
33
+ # @see format_code
34
+ def format_code=(v='General')
35
+ Axlsx::validate_string(v)
36
+ @format_code = v
37
+ end
38
+
39
+ # serialize the object
40
+ def to_xml_string(str = "")
41
+ str << '<c:' << @tag_name.to_s << '>'
42
+ str << '<c:formatCode>' << format_code.to_s << '</c:formatCode>'
43
+ str << '<c:ptCount val="' << @pt.size.to_s << '"/>'
44
+ @pt.each_with_index do |num_val, index|
45
+ num_val.to_xml_string index, str
46
+ end
47
+ str << '</c:' << @tag_name.to_s << '>'
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,61 @@
1
+ module Axlsx
2
+
3
+ # A numeric data source for use by charts.
4
+ class NumDataSource
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
18
+
19
+ # creates a new NumDataSource object
20
+ # @option options [Array] data An array of Cells or Numeric objects
21
+ # @option options [Symbol] tag_name see tag_name
22
+ def initialize(options={})
23
+ # override these three in child classes
24
+ @data_type ||= NumData
25
+ @tag_name ||= :val
26
+ @ref_tag_name ||= :numRef
27
+
28
+ @f = nil
29
+ @data = @data_type.new(options)
30
+ if options[:data] && options[:data].first.is_a?(Cell)
31
+ @f = Axlsx::cell_range(options[:data])
32
+ end
33
+ options.each do |o|
34
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
35
+ end
36
+ end
37
+
38
+ # sets the tag name for this data source
39
+ # @param [Symbol] v One of the allowed_tag_names
40
+ def tag_name=(v)
41
+ Axlsx::RestrictionValidator.validate "#{self.class.name}.tag_name", self.class.allowed_tag_names, v
42
+ @tag_name = v
43
+ end
44
+
45
+ # serialize the object
46
+ # @param [String] str
47
+ def to_xml_string(str="")
48
+ str << '<c:' << tag_name.to_s << '>'
49
+ if @f
50
+ str << '<c:' << @ref_tag_name.to_s << '>'
51
+ str << '<c:f>' << @f.to_s << '</c:f>'
52
+ end
53
+ @data.to_xml_string str
54
+ if @f
55
+ str << '</c:' << @ref_tag_name.to_s << '>'
56
+ end
57
+ str << '</c:' << tag_name.to_s << '>'
58
+ end
59
+ end
60
+ end
61
+
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Axlsx
3
+
4
+ #This class specifies data for a particular data point.
5
+ class NumVal < StrVal
6
+
7
+ # A string representing the format code to apply.
8
+ # For more information see see the SpreadsheetML numFmt element's (§18.8.30) formatCode attribute.
9
+ # @return [String]
10
+ attr_reader :format_code
11
+
12
+ # creates a new NumVal object
13
+ # @option options [String] formatCode
14
+ # @option options [Integer] v
15
+ def initialize(options={})
16
+ @format_code = "General"
17
+ super(options)
18
+ end
19
+
20
+ # @see format_code
21
+ def format_code=(v)
22
+ Axlsx::validate_string(v)
23
+ @format_code = v
24
+ end
25
+
26
+ # serialize the object
27
+ def to_xml_string(idx, str = "")
28
+ Axlsx::validate_unsigned_int(idx)
29
+ str << '<c:pt idx="' << idx.to_s << '" formatCode="' << format_code << '"><c:v>' << v.to_s << '</c:v></c:pt>'
30
+ end
31
+ end
32
+ end
@@ -90,8 +90,7 @@ module Axlsx
90
90
  # @return [String]
91
91
  def extname
92
92
  File.extname(image_src).delete('.') unless image_src.nil?
93
- end
94
-
93
+ end
95
94
  # The index of this image in the workbooks images collections
96
95
  # @return [Index]
97
96
  def index
@@ -113,27 +112,32 @@ module Axlsx
113
112
  # @param [Integer] v
114
113
  # @see OneCellAnchor.width
115
114
  def width
115
+ return unless @anchor.is_a?(OneCellAnchor)
116
116
  @anchor.width
117
117
  end
118
118
 
119
119
  # @see width
120
120
  def width=(v)
121
+ use_one_cell_anchor unless @anchor.is_a?(OneCellAnchor)
121
122
  @anchor.width = v
122
123
  end
123
124
 
124
125
  # providing access to update the anchor's height attribute
125
126
  # @param [Integer] v
126
127
  # @see OneCellAnchor.width
128
+ # @note this is a noop if you are using a TwoCellAnchor
127
129
  def height
128
130
  @anchor.height
129
131
  end
130
132
 
131
133
  # @see height
134
+ # @note This is a noop if you are using a TwoCellAnchor
132
135
  def height=(v)
136
+ use_one_cell_anchor unless @anchor.is_a?(OneCellAnchor)
133
137
  @anchor.height = v
134
138
  end
135
-
136
- # This is a short cut method to set the start anchor position
139
+
140
+ # This is a short cut method to set the start anchor position
137
141
  # If you need finer granularity in positioning use
138
142
  # graphic_frame.anchor.from.colOff / rowOff
139
143
  # @param [Integer] x The column
@@ -142,6 +146,18 @@ module Axlsx
142
146
  def start_at(x, y)
143
147
  @anchor.from.col = x
144
148
  @anchor.from.row = y
149
+ @anchor.from
150
+ end
151
+
152
+ # noop if not using a two cell anchor
153
+ # @param [Integer] x The column
154
+ # @param [Integer] y The row
155
+ # @return [Marker]
156
+ def end_at(x, y)
157
+ use_two_cell_anchor unless @anchor.is_a?(TwoCellAnchor)
158
+ @anchor.to.col = x
159
+ @anchor.to.row = y
160
+ @anchor.to
145
161
  end
146
162
 
147
163
  # Serializes the object
@@ -162,6 +178,30 @@ module Axlsx
162
178
  str << '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic>'
163
179
 
164
180
  end
181
+
182
+ private
183
+
184
+ # Changes the anchor to a one cell anchor.
185
+ def use_one_cell_anchor
186
+ return if @anchor.is_a?(OneCellAnchor)
187
+ swap_anchor(OneCellAnchor.new(@anchor.drawing, :from => @anchor.from))
188
+ end
189
+
190
+ #changes the anchor type to a two cell anchor
191
+ def use_two_cell_anchor
192
+ return if @anchor.is_a?(TwoCellAnchor)
193
+ swap_anchor(TwoCellAnchor.new(@anchor.drawing)).tap do |new_anchor|
194
+ new_anchor.from.col = @anchor.from.col
195
+ new_anchor.from.row = @anchor.from.row
196
+ end
197
+ end
198
+
199
+ # refactoring of swapping code, law of demeter be damned!
200
+ def swap_anchor(new_anchor)
201
+ new_anchor.drawing.anchors.delete(new_anchor)
202
+ @anchor.drawing.anchors[@anchor.drawing.anchors.index(@anchor)] = new_anchor
203
+ @anchor = new_anchor
204
+ end
165
205
 
166
206
  end
167
207
  end
@@ -13,19 +13,20 @@ module Axlsx
13
13
  # @option options [Cell, String] title
14
14
  # @option options [Boolean] show_legend
15
15
  # @option options [Symbol] grouping
16
- # @option options [String] gapDepth
17
- # @option options [Integer] rotX
18
- # @option options [String] hPercent
19
- # @option options [Integer] rotY
20
- # @option options [String] depthPercent
21
- # @option options [Boolean] rAngAx
16
+ # @option options [String] gap_depth
17
+ # @option options [Integer] rot_x
18
+ # @option options [String] h_percent
19
+ # @option options [Integer] rot_y
20
+ # @option options [String] depth_percent
21
+ # @option options [Boolean] r_ang_ax
22
22
  # @option options [Integer] perspective
23
23
  # @see Chart
24
24
  # @see View3D
25
25
  def initialize(frame, options={})
26
26
  super(frame, options)
27
27
  @series_type = PieSeries
28
- @view3D = View3D.new({:rotX=>30, :perspective=>30}.merge(options))
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
@@ -19,6 +19,9 @@ module Axlsx
19
19
  # @return [Integert]
20
20
  attr_reader :explosion
21
21
 
22
+ # An array of rgb colors to apply to your bar chart.
23
+ attr_reader :colors
24
+
22
25
  # Creates a new series
23
26
  # @option options [Array, SimpleTypedList] data
24
27
  # @option options [Array, SimpleTypedList] labels
@@ -27,11 +30,15 @@ module Axlsx
27
30
  # @param [Chart] chart
28
31
  def initialize(chart, options={})
29
32
  @explosion = nil
33
+ @colors = []
30
34
  super(chart, options)
31
- self.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
32
- self.data = ValAxisData.new(options[:data]) unless options[:data].nil?
35
+ self.labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
36
+ self.data = NumDataSource.new(options) unless options[:data].nil?
33
37
  end
34
38
 
39
+ # @see colors
40
+ def colors=(v) DataTypeValidator.validate "BarSeries.colors", [Array], v; @colors = v end
41
+
35
42
  # @see explosion
36
43
  def explosion=(v) Axlsx::validate_unsigned_int(v); @explosion = v; end
37
44
 
@@ -41,6 +48,13 @@ module Axlsx
41
48
  def to_xml_string(str = '')
42
49
  super(str) do |str_inner|
43
50
  str_inner << '<c:explosion val="' << @explosion << '"/>' unless @explosion.nil?
51
+ colors.each_with_index do |c, index|
52
+ str << '<c:dPt>'
53
+ str << '<c:idx val="' << index.to_s << '"/>'
54
+ str << '<c:spPr><a:solidFill>'
55
+ str << '<a:srgbClr val="' << c << '"/>'
56
+ str << '</a:solidFill></c:spPr></c:dPt>'
57
+ end
44
58
  @labels.to_xml_string str_inner unless @labels.nil?
45
59
  @data.to_xml_string str_inner unless @data.nil?
46
60
  end
@@ -50,10 +64,10 @@ module Axlsx
50
64
  private
51
65
 
52
66
  # assigns the data for this series
53
- def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
67
+ def data=(v) DataTypeValidator.validate "Series.data", [NumDataSource], v; @data = v; end
54
68
 
55
69
  # assigns the labels for this series
56
- def labels=(v) DataTypeValidator.validate "Series.labels", [SimpleTypedList], v; @labels = v; end
70
+ def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
57
71
 
58
72
  end
59
73
 
@@ -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
@@ -44,24 +45,17 @@ module Axlsx
44
45
  # @param [String] str
45
46
  # @return [String]
46
47
  def to_xml_string(str = '')
47
- super do |str|
48
- str << '<c:scatterChart>'
49
- str << '<c:scatterStyle val="' << scatterStyle.to_s << '"/>'
50
- str << '<c:varyColors val="1"/>'
51
- @series.each { |ser| ser.to_xml_string(str) }
52
- str << '<c:dLbls>'
53
- str << '<c:showLegendKey val="0"/>'
54
- str << '<c:showVal val="0"/>'
55
- str << '<c:showCatName val="0"/>'
56
- str << '<c:showSerName val="0"/>'
57
- str << '<c:showPercent val="0"/>'
58
- str << '<c:showBubbleSize val="0"/>'
59
- str << '</c:dLbls>'
60
- str << '<c:axId val="' << @xValAxId.to_s << '"/>'
61
- str << '<c:axId val="' << @yValAxId.to_s << '"/>'
62
- str << '</c:scatterChart>'
63
- @xValAxis.to_xml_string str
64
- @yValAxis.to_xml_string str
48
+ super(str) do |str_inner|
49
+ str_inner << '<c:scatterChart>'
50
+ str_inner << '<c:scatterStyle val="' << scatterStyle.to_s << '"/>'
51
+ str_inner << '<c:varyColors val="1"/>'
52
+ @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 << '"/>'
56
+ str_inner << '</c:scatterChart>'
57
+ @xValAxis.to_xml_string str_inner
58
+ @yValAxis.to_xml_string str_inner
65
59
  end
66
60
  str
67
61
  end
@@ -16,13 +16,22 @@ module Axlsx
16
16
  # @return [NamedAxisData]
17
17
  attr_reader :yData
18
18
 
19
+ # The fill color for this series.
20
+ # Red, green, and blue is expressed as sequence of hex digits, RRGGBB. A perceptual gamma of 2.2 is used.
21
+ # @return [String]
22
+ attr_reader :color
23
+
19
24
  # Creates a new ScatterSeries
20
25
  def initialize(chart, options={})
21
26
  @xData, @yData = nil
22
27
  super(chart, options)
28
+ @xData = AxDataSource.new(:tag_name => :xVal, :data => options[:xData]) unless options[:xData].nil?
29
+ @yData = NumDataSource.new({:tag_name => :yVal, :data => options[:yData]}) unless options[:yData].nil?
30
+ end
23
31
 
24
- @xData = NamedAxisData.new("xVal", options[:xData]) unless options[:xData].nil?
25
- @yData = NamedAxisData.new("yVal", options[:yData]) unless options[:yData].nil?
32
+ # @see color
33
+ def color=(v)
34
+ @color = v
26
35
  end
27
36
 
28
37
  # Serializes the object
@@ -30,6 +39,23 @@ module Axlsx
30
39
  # @return [String]
31
40
  def to_xml_string(str = '')
32
41
  super(str) do |inner_str|
42
+ # needs to override the super color here to push in ln/and something else!
43
+ if color
44
+ str << '<c:spPr><a:solidFill>'
45
+ str << '<a:srgbClr val="' << color << '"/>'
46
+ str << '</a:solidFill>'
47
+ str << '<a:ln><a:solidFill>'
48
+ str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
49
+ str << '</c:spPr>'
50
+ str << '<c:marker>'
51
+ str << '<c:spPr><a:solidFill>'
52
+ str << '<a:srgbClr val="' << color << '"/>'
53
+ str << '</a:solidFill>'
54
+ str << '<a:ln><a:solidFill>'
55
+ str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
56
+ str << '</c:spPr>'
57
+ str << '</c:marker>'
58
+ end
33
59
  @xData.to_xml_string(inner_str) unless @xData.nil?
34
60
  @yData.to_xml_string(inner_str) unless @yData.nil?
35
61
  end
@@ -20,7 +20,7 @@ module Axlsx
20
20
  # @option options [Integer] tickLblSkip
21
21
  # @option options [Integer] tickMarkSkip
22
22
  def initialize(axId, crossAx, options={})
23
- @tickLblSkip, @tickMarkSkip = nil, nil
23
+ @tickLblSkip, @tickMarkSkip = 1, 1
24
24
  super(axId, crossAx, options)
25
25
  end
26
26
 
@@ -27,6 +27,7 @@ module Axlsx
27
27
  end
28
28
  end
29
29
 
30
+
30
31
  # The index of this series in the chart's series.
31
32
  # @return [Integer]
32
33
  def index
@@ -66,7 +67,6 @@ module Axlsx
66
67
  yield str if block_given?
67
68
  str << '</c:ser>'
68
69
  end
69
-
70
70
  end
71
71
 
72
72
  end