axlsx 1.0.16 → 1.1.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 (173) hide show
  1. data/.yardopts +1 -0
  2. data/CHANGELOG.md +18 -3
  3. data/README.md +189 -55
  4. data/examples/example.csv +1000 -0
  5. data/examples/example.rb +264 -142
  6. data/examples/example.xlsx +0 -0
  7. data/examples/example_streamed.xlsx +0 -0
  8. data/examples/no-use_autowidth.xlsx +0 -0
  9. data/examples/shared_strings_example.xlsx +0 -0
  10. data/lib/axlsx/content_type/content_type.rb +13 -12
  11. data/lib/axlsx/content_type/default.rb +10 -6
  12. data/lib/axlsx/content_type/override.rb +13 -8
  13. data/lib/axlsx/doc_props/app.rb +38 -41
  14. data/lib/axlsx/doc_props/core.rb +13 -17
  15. data/lib/axlsx/drawing/axis.rb +39 -19
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +34 -32
  17. data/lib/axlsx/drawing/bar_series.rb +14 -14
  18. data/lib/axlsx/drawing/cat_axis.rb +16 -14
  19. data/lib/axlsx/drawing/cat_axis_data.rb +17 -18
  20. data/lib/axlsx/drawing/chart.rb +40 -41
  21. data/lib/axlsx/drawing/drawing.rb +16 -12
  22. data/lib/axlsx/drawing/graphic_frame.rb +22 -21
  23. data/lib/axlsx/drawing/hyperlink.rb +13 -12
  24. data/lib/axlsx/drawing/line_3D_chart.rb +31 -28
  25. data/lib/axlsx/drawing/line_series.rb +12 -11
  26. data/lib/axlsx/drawing/marker.rb +11 -8
  27. data/lib/axlsx/drawing/named_axis_data.rb +36 -0
  28. data/lib/axlsx/drawing/one_cell_anchor.rb +18 -16
  29. data/lib/axlsx/drawing/pic.rb +26 -38
  30. data/lib/axlsx/drawing/picture_locking.rb +22 -18
  31. data/lib/axlsx/drawing/pie_3D_chart.rb +11 -8
  32. data/lib/axlsx/drawing/pie_series.rb +16 -12
  33. data/lib/axlsx/drawing/scaling.rb +11 -10
  34. data/lib/axlsx/drawing/scatter_chart.rb +69 -0
  35. data/lib/axlsx/drawing/scatter_series.rb +39 -0
  36. data/lib/axlsx/drawing/ser_axis.rb +11 -10
  37. data/lib/axlsx/drawing/series.rb +16 -15
  38. data/lib/axlsx/drawing/series_title.rb +15 -14
  39. data/lib/axlsx/drawing/title.rb +27 -26
  40. data/lib/axlsx/drawing/two_cell_anchor.rb +19 -20
  41. data/lib/axlsx/drawing/val_axis.rb +9 -7
  42. data/lib/axlsx/drawing/val_axis_data.rb +18 -17
  43. data/lib/axlsx/drawing/view_3D.rb +23 -20
  44. data/lib/axlsx/package.rb +116 -51
  45. data/lib/axlsx/rels/relationship.rb +12 -8
  46. data/lib/axlsx/rels/relationships.rb +8 -1
  47. data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
  48. data/lib/axlsx/stylesheet/border.rb +28 -23
  49. data/lib/axlsx/stylesheet/border_pr.rb +17 -15
  50. data/lib/axlsx/stylesheet/cell_alignment.rb +24 -21
  51. data/lib/axlsx/stylesheet/cell_protection.rb +11 -7
  52. data/lib/axlsx/stylesheet/cell_style.rb +9 -5
  53. data/lib/axlsx/stylesheet/color.rb +21 -14
  54. data/lib/axlsx/stylesheet/fill.rb +8 -5
  55. data/lib/axlsx/stylesheet/font.rb +22 -14
  56. data/lib/axlsx/stylesheet/gradient_fill.rb +20 -17
  57. data/lib/axlsx/stylesheet/gradient_stop.rb +10 -6
  58. data/lib/axlsx/stylesheet/num_fmt.rb +13 -6
  59. data/lib/axlsx/stylesheet/pattern_fill.rb +26 -10
  60. data/lib/axlsx/stylesheet/styles.rb +53 -41
  61. data/lib/axlsx/stylesheet/table_style.rb +10 -4
  62. data/lib/axlsx/stylesheet/table_style_element.rb +11 -7
  63. data/lib/axlsx/stylesheet/table_styles.rb +12 -8
  64. data/lib/axlsx/stylesheet/xf.rb +30 -25
  65. data/lib/axlsx/util/cbf.rb +1 -0
  66. data/lib/axlsx/util/constants.rb +27 -14
  67. data/lib/axlsx/util/ms_off_crypto.rb +1 -1
  68. data/lib/axlsx/util/parser.rb +1 -0
  69. data/lib/axlsx/util/simple_typed_list.rb +20 -10
  70. data/lib/axlsx/util/storage.rb +1 -0
  71. data/lib/axlsx/util/validators.rb +23 -7
  72. data/lib/axlsx/version.rb +2 -1
  73. data/lib/axlsx/workbook/shared_strings_table.rb +69 -0
  74. data/lib/axlsx/workbook/shared_strings_table.rb~ +69 -0
  75. data/lib/axlsx/workbook/workbook.rb +81 -35
  76. data/lib/axlsx/workbook/worksheet/cell.rb +172 -117
  77. data/lib/axlsx/workbook/worksheet/col.rb +114 -0
  78. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  79. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
  80. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
  81. data/lib/axlsx/workbook/worksheet/row.rb +53 -21
  82. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  83. data/lib/axlsx/workbook/worksheet/table.rb +96 -0
  84. data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
  85. data/lib/axlsx/workbook/worksheet/worksheet.rb +269 -121
  86. data/lib/axlsx.rb +41 -14
  87. data/lib/schema/dc.xsd +5 -5
  88. data/lib/schema/dcmitype.xsd +5 -3
  89. data/lib/schema/dcterms.xsd +15 -15
  90. data/lib/schema/opc-coreProperties.xsd +6 -2
  91. data/lib/schema/xml.xsd +7 -8
  92. data/test/#benchmark.txt# +7 -0
  93. data/test/#tc_helper.rb# +3 -0
  94. data/test/benchmark.rb +81 -0
  95. data/test/benchmark.rb~ +0 -0
  96. data/test/benchmark.txt +6 -0
  97. data/test/benchmark.txt~ +6 -0
  98. data/test/content_type/tc_content_type.rb +31 -31
  99. data/test/content_type/tc_default.rb +9 -22
  100. data/test/content_type/tc_override.rb +8 -21
  101. data/test/doc_props/tc_app.rb +2 -8
  102. data/test/doc_props/tc_core.rb +6 -7
  103. data/test/drawing/tc_axis.rb +7 -3
  104. data/test/drawing/tc_bar_3D_chart.rb +6 -7
  105. data/test/drawing/tc_bar_series.rb +4 -5
  106. data/test/drawing/tc_cat_axis.rb +2 -3
  107. data/test/drawing/tc_cat_axis_data.rb +2 -3
  108. data/test/drawing/tc_chart.rb +13 -14
  109. data/test/drawing/tc_drawing.rb +7 -8
  110. data/test/drawing/tc_graphic_frame.rb +3 -4
  111. data/test/drawing/tc_hyperlink.rb +2 -3
  112. data/test/drawing/tc_line_3d_chart.rb +5 -6
  113. data/test/drawing/tc_line_series.rb +3 -4
  114. data/test/drawing/tc_marker.rb +3 -4
  115. data/test/drawing/tc_one_cell_anchor.rb +6 -7
  116. data/test/drawing/tc_pic.rb +8 -9
  117. data/test/drawing/tc_picture_locking.rb +2 -3
  118. data/test/drawing/tc_pie_3D_chart.rb +5 -6
  119. data/test/drawing/tc_pie_series.rb +4 -5
  120. data/test/drawing/tc_scaling.rb +3 -4
  121. data/test/drawing/tc_scatter_chart.rb +43 -0
  122. data/test/drawing/tc_scatter_series.rb +20 -0
  123. data/test/drawing/tc_ser_axis.rb +2 -3
  124. data/test/drawing/tc_series.rb +4 -5
  125. data/test/drawing/tc_series_title.rb +4 -5
  126. data/test/drawing/tc_title.rb +4 -5
  127. data/test/drawing/tc_two_cell_anchor.rb +4 -5
  128. data/test/drawing/tc_val_axis.rb +2 -3
  129. data/test/drawing/tc_val_axis_data.rb +2 -3
  130. data/test/drawing/tc_view_3D.rb +6 -7
  131. data/test/example.csv +1000 -0
  132. data/test/example.xlsx +0 -0
  133. data/test/example_streamed.xlsx +0 -0
  134. data/test/profile.rb +33 -0
  135. data/test/rels/tc_relationship.rb +5 -6
  136. data/test/rels/tc_relationships.rb +4 -5
  137. data/test/stylesheet/tc_border.rb +3 -4
  138. data/test/stylesheet/tc_border_pr.rb +3 -4
  139. data/test/stylesheet/tc_cell_alignment.rb +10 -6
  140. data/test/stylesheet/tc_cell_protection.rb +2 -3
  141. data/test/stylesheet/tc_cell_style.rb +2 -3
  142. data/test/stylesheet/tc_color.rb +2 -3
  143. data/test/stylesheet/tc_fill.rb +1 -2
  144. data/test/stylesheet/tc_font.rb +12 -5
  145. data/test/stylesheet/tc_gradient_fill.rb +1 -2
  146. data/test/stylesheet/tc_gradient_stop.rb +1 -2
  147. data/test/stylesheet/tc_num_fmt.rb +1 -2
  148. data/test/stylesheet/tc_pattern_fill.rb +3 -4
  149. data/test/stylesheet/tc_styles.rb +16 -6
  150. data/test/stylesheet/tc_table_style.rb +2 -3
  151. data/test/stylesheet/tc_table_style_element.rb +2 -3
  152. data/test/stylesheet/tc_table_styles.rb +3 -4
  153. data/test/stylesheet/tc_xf.rb +16 -17
  154. data/test/tc_axlsx.rb +39 -0
  155. data/test/tc_axlsx.rb~ +0 -0
  156. data/test/tc_helper.rb +3 -0
  157. data/test/tc_helper.rb~ +3 -0
  158. data/test/tc_package.rb +43 -9
  159. data/test/util/tc_simple_typed_list.rb +8 -9
  160. data/test/util/tc_validators.rb +7 -8
  161. data/test/workbook/tc_shared_strings_table.rb +38 -0
  162. data/test/workbook/tc_workbook.rb +32 -6
  163. data/test/workbook/worksheet/table/tc_table.rb +71 -0
  164. data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
  165. data/test/workbook/worksheet/tc_cell.rb +70 -13
  166. data/test/workbook/worksheet/tc_col.rb +59 -0
  167. data/test/workbook/worksheet/tc_col.rb~ +10 -0
  168. data/test/workbook/worksheet/tc_date_time_converter.rb +126 -0
  169. data/test/workbook/worksheet/tc_page_margins.rb +97 -0
  170. data/test/workbook/worksheet/tc_row.rb +54 -4
  171. data/test/workbook/worksheet/tc_worksheet.rb +191 -31
  172. metadata +162 -109
  173. data/test/drawing/tc_hyperlink.rb~ +0 -71
@@ -1,4 +1,4 @@
1
- # -*- coding: utf-8 -*-
1
+ # encoding: UTF-8
2
2
  module Axlsx
3
3
  # a Pic object represents an image in your worksheet
4
4
  # Worksheet#add_image is the recommended way to manage images in your sheets
@@ -28,7 +28,7 @@ module Axlsx
28
28
 
29
29
  # The picture locking attributes for this picture
30
30
  attr_reader :picture_locking
31
-
31
+
32
32
  # Creates a new Pic(ture) object
33
33
  # @param [Anchor] anchor the anchor that holds this image
34
34
  # @option options [String] name
@@ -39,6 +39,7 @@ module Axlsx
39
39
  # @option options [Intger] height
40
40
  def initialize(anchor, options={})
41
41
  @anchor = anchor
42
+ @hyperlink = nil
42
43
  @anchor.drawing.worksheet.workbook.images << self
43
44
  options.each do |o|
44
45
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
@@ -49,7 +50,7 @@ module Axlsx
49
50
  end
50
51
 
51
52
  attr_reader :hyperlink
52
-
53
+
53
54
  # sets or updates a hyperlink for this image.
54
55
  # @param [String] v The href value for the hyper link
55
56
  # @option options @see Hyperlink#initialize All options available to the Hyperlink class apply - however href will be overridden with the v parameter value.
@@ -65,7 +66,7 @@ module Axlsx
65
66
  @hyperlink
66
67
  end
67
68
 
68
- def image_src=(v)
69
+ def image_src=(v)
69
70
  Axlsx::validate_string(v)
70
71
  RestrictionValidator.validate 'Pic.image_src', ALLOWED_EXTENSIONS, File.extname(v).delete('.')
71
72
  raise ArgumentError, "File does not exist" unless File.exist?(v)
@@ -83,8 +84,8 @@ module Axlsx
83
84
  # @return [String]
84
85
  def file_name
85
86
  File.basename(image_src) unless image_src.nil?
86
- end
87
-
87
+ end
88
+
88
89
  # returns the extension of image_src without the preceeding '.'
89
90
  # @return [String]
90
91
  def extname
@@ -92,7 +93,7 @@ module Axlsx
92
93
  end
93
94
 
94
95
  # The index of this image in the workbooks images collections
95
- # @return [Index]
96
+ # @return [Index]
96
97
  def index
97
98
  @anchor.drawing.worksheet.workbook.images.index(self)
98
99
  end
@@ -119,7 +120,7 @@ module Axlsx
119
120
  def width=(v)
120
121
  @anchor.width = v
121
122
  end
122
-
123
+
123
124
  # providing access to update the anchor's height attribute
124
125
  # @param [Integer] v
125
126
  # @see OneCellAnchor.width
@@ -143,37 +144,24 @@ module Axlsx
143
144
  @anchor.from.row = y
144
145
  end
145
146
 
146
- # Serializes the picture
147
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
147
+ # Serializes the object
148
+ # @param [String] str
148
149
  # @return [String]
149
- def to_xml(xml)
150
- xml.pic {
151
- xml.nvPicPr {
152
- xml.cNvPr(:id=>"2", :name=>name, :descr=>descr) {
153
- if @hyperlink.is_a?(Hyperlink)
154
- @hyperlink.to_xml(xml)
155
- end
156
- }
157
- xml.cNvPicPr {
158
- picture_locking.to_xml(xml)
159
- }
160
- }
161
- xml.blipFill {
162
- xml[:a].blip :'xmlns:r' => XML_NS_R, :'r:embed'=>"rId#{id}"
163
- xml[:a].stretch {
164
- xml.fillRect
165
- }
166
- }
167
- xml.spPr {
168
- xml[:a].xfrm {
169
- xml.off :x=>0, :y=>0
170
- xml.ext :cx=>2336800, :cy=>2161540
171
- }
172
- xml[:a].prstGeom(:prst=>:rect) {
173
- xml.avLst
174
- }
175
- }
176
- }
150
+ def to_xml_string(str = '')
151
+ str << '<xdr:pic>'
152
+ str << '<xdr:nvPicPr>'
153
+ str << '<xdr:cNvPr id="2" name="' << name.to_s << '" descr="' << descr.to_s << '">'
154
+ @hyperlink.to_xml_string(str) if @hyperlink.is_a?(Hyperlink)
155
+ str << '</xdr:cNvPr><xdr:cNvPicPr>'
156
+ picture_locking.to_xml_string(str)
157
+ str << '</xdr:cNvPicPr></xdr:nvPicPr>'
158
+ str << '<xdr:blipFill>'
159
+ str << '<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="rId' << id.to_s << '"/>'
160
+ str << '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr>'
161
+ str << '<a:xfrm><a:off x="0" y="0"/><a:ext cx="2336800" cy="2161540"/></a:xfrm>'
162
+ str << '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic>'
163
+
177
164
  end
165
+
178
166
  end
179
167
  end
@@ -1,8 +1,9 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
- # The picture locking class defines the locking properties for pictures in your workbook.
3
+ # The picture locking class defines the locking properties for pictures in your workbook.
3
4
  class PictureLocking
4
-
5
-
5
+
6
+
6
7
  attr_reader :noGrp
7
8
  attr_reader :noSelect
8
9
  attr_reader :noRot
@@ -30,43 +31,46 @@ module Axlsx
30
31
  options.each do |o|
31
32
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
32
33
  end
33
- end
34
+ end
34
35
 
35
36
  # @see noGrp
36
- def noGrp=(v) Axlsx::validate_boolean v; @noGrp = v end
37
+ def noGrp=(v) Axlsx::validate_boolean v; @noGrp = v end
37
38
 
38
39
  # @see noSelect
39
- def noSelect=(v) Axlsx::validate_boolean v; @noSelect = v end
40
+ def noSelect=(v) Axlsx::validate_boolean v; @noSelect = v end
40
41
 
41
42
  # @see noRot
42
- def noRot=(v) Axlsx::validate_boolean v; @noRot = v end
43
+ def noRot=(v) Axlsx::validate_boolean v; @noRot = v end
43
44
 
44
45
  # @see noChangeAspect
45
- def noChangeAspect=(v) Axlsx::validate_boolean v; @noChangeAspect = v end
46
+ def noChangeAspect=(v) Axlsx::validate_boolean v; @noChangeAspect = v end
46
47
 
47
48
  # @see noMove
48
- def noMove=(v) Axlsx::validate_boolean v; @noMove = v end
49
+ def noMove=(v) Axlsx::validate_boolean v; @noMove = v end
49
50
 
50
51
  # @see noResize
51
- def noResize=(v) Axlsx::validate_boolean v; @noResize = v end
52
+ def noResize=(v) Axlsx::validate_boolean v; @noResize = v end
52
53
 
53
54
  # @see noEditPoints
54
- def noEditPoints=(v) Axlsx::validate_boolean v; @noEditPoints = v end
55
+ def noEditPoints=(v) Axlsx::validate_boolean v; @noEditPoints = v end
55
56
 
56
57
  # @see noAdjustHandles
57
- def noAdjustHandles=(v) Axlsx::validate_boolean v; @noAdjustHandles = v end
58
+ def noAdjustHandles=(v) Axlsx::validate_boolean v; @noAdjustHandles = v end
58
59
 
59
60
  # @see noChangeArrowheads
60
- def noChangeArrowheads=(v) Axlsx::validate_boolean v; @noChangeArrowheads = v end
61
+ def noChangeArrowheads=(v) Axlsx::validate_boolean v; @noChangeArrowheads = v end
61
62
 
62
63
  # @see noChangeShapeType
63
- def noChangeShapeType=(v) Axlsx::validate_boolean v; @noChangeShapeType = v end
64
+ def noChangeShapeType=(v) Axlsx::validate_boolean v; @noChangeShapeType = v end
64
65
 
65
- # Serializes the picture locking
66
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
66
+ # Serializes the object
67
+ # @param [String] str
67
68
  # @return [String]
68
- def to_xml(xml)
69
- xml[:a].picLocks(self.instance_values)
69
+ def to_xml_string(str = '')
70
+ str << '<a:picLocks '
71
+ str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
72
+ str << '/>'
70
73
  end
74
+
71
75
  end
72
76
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
 
3
4
 
@@ -10,7 +11,7 @@ module Axlsx
10
11
  # Creates a new pie chart object
11
12
  # @param [GraphicFrame] frame The workbook that owns this chart.
12
13
  # @option options [Cell, String] title
13
- # @option options [Boolean] show_legend
14
+ # @option options [Boolean] show_legend
14
15
  # @option options [Symbol] grouping
15
16
  # @option options [String] gapDepth
16
17
  # @option options [Integer] rotX
@@ -27,15 +28,17 @@ module Axlsx
27
28
  @view3D = View3D.new({:rotX=>30, :perspective=>30}.merge(options))
28
29
  end
29
30
 
30
- # Serializes the pie chart
31
+ # Serializes the object
32
+ # @param [String] str
31
33
  # @return [String]
32
- def to_xml
33
- super() do |xml|
34
- xml[:c].pie3DChart {
35
- xml[:c].varyColors :val=>1
36
- @series.each { |ser| ser.to_xml(xml) }
37
- }
34
+ def to_xml_string(str = '')
35
+ super(str) do |str_inner|
36
+ str_inner << '<c:pie3DChart>'
37
+ str_inner << '<c:varyColors val="1"/>'
38
+ @series.each { |ser| ser.to_xml_string(str_inner) }
39
+ str_inner << '</c:pie3DChart>'
38
40
  end
39
41
  end
42
+
40
43
  end
41
44
  end
@@ -1,11 +1,13 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
3
+
2
4
  # A PieSeries defines the data and labels and explosion for pie charts series.
3
5
  # @note The recommended way to manage series is to use Chart#add_series
4
6
  # @see Worksheet#add_chart
5
7
  # @see Chart#add_series
6
8
  class PieSeries < Series
7
9
 
8
- # The data for this series.
10
+ # The data for this series.
9
11
  # @return [SimpleTypedList]
10
12
  attr_reader :data
11
13
 
@@ -28,22 +30,24 @@ module Axlsx
28
30
  super(chart, options)
29
31
  self.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
30
32
  self.data = ValAxisData.new(options[:data]) unless options[:data].nil?
31
- end
32
-
33
+ end
34
+
33
35
  # @see explosion
34
36
  def explosion=(v) Axlsx::validate_unsigned_int(v); @explosion = v; end
35
37
 
36
- # Serializes the series
37
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
38
+ # Serializes the object
39
+ # @param [String] str
38
40
  # @return [String]
39
- def to_xml(xml)
40
- super(xml) do |xml_inner|
41
- xml_inner.explosion :val=>@explosion unless @explosion.nil?
42
- @labels.to_xml(xml_inner) unless @labels.nil?
43
- @data.to_xml(xml_inner) unless @data.nil?
44
- end
41
+ def to_xml_string(str = '')
42
+ super(str) do |str_inner|
43
+ str_inner << '<c:explosion val="' << @explosion << '"/>' unless @explosion.nil?
44
+ @labels.to_xml_string str_inner unless @labels.nil?
45
+ @data.to_xml_string str_inner unless @data.nil?
46
+ end
47
+ str
45
48
  end
46
- private
49
+
50
+ private
47
51
 
48
52
  # assigns the data for this series
49
53
  def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # The Scaling class defines axis scaling
3
4
  class Scaling
@@ -32,7 +33,7 @@ module Axlsx
32
33
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
33
34
  end
34
35
  end
35
-
36
+
36
37
  # @see logBase
37
38
  def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer, Fixnum], v, lambda { |arg| arg >= 2 && arg <= 1000}; @logBase = v; end
38
39
  # @see orientation
@@ -43,16 +44,16 @@ module Axlsx
43
44
  # @see min
44
45
  def min=(v) DataTypeValidator.validate "Scaling.min", Float, v; @min = v; end
45
46
 
46
- # Serializes the axId
47
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
47
+ # Serializes the object
48
+ # @param [String] str
48
49
  # @return [String]
49
- def to_xml(xml)
50
- xml[:c].scaling {
51
- xml[:c].logBase :val=> @logBase unless @logBase.nil?
52
- xml[:c].orientation :val=> @orientation unless @orientation.nil?
53
- xml[:c].min :val => @min unless @min.nil?
54
- xml[:c].max :val => @max unless @max.nil?
55
- }
50
+ def to_xml_string(str = '')
51
+ str << '<c:scaling>'
52
+ str << '<c:logBase val="' << @logBase.to_s << '"/>' unless @logBase.nil?
53
+ str << '<c:orientation val="' << @orientation.to_s << '"/>' unless @orientation.nil?
54
+ str << '<c:min val="' << @min.to_s << '"/>' unless @min.nil?
55
+ str << '<c:max val="' << @max.to_s << '"/>' unless @max.nil?
56
+ str << '</c:scaling>'
56
57
  end
57
58
 
58
59
  end
@@ -0,0 +1,69 @@
1
+ # encoding: UTF-8
2
+ module Axlsx
3
+
4
+ # The ScatterChart allows you to insert a scatter chart into your worksheet
5
+ # @see Worksheet#add_chart
6
+ # @see Chart#add_series
7
+ # @see README for an example
8
+ class ScatterChart < Chart
9
+
10
+ # The Style for the scatter chart
11
+ # must be one of :none | :line | :lineMarker | :marker | :smooth | :smoothMarker
12
+ # return [Symbol]
13
+ attr_reader :scatterStyle
14
+
15
+ # the x value axis
16
+ # @return [ValAxis]
17
+ attr_reader :xValAxis
18
+
19
+ # the y value axis
20
+ # @return [ValAxis]
21
+ attr_reader :yValAxis
22
+
23
+ # Creates a new scatter chart
24
+ 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)
31
+ @series_type = ScatterSeries
32
+ options.each do |o|
33
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
34
+ end
35
+ end
36
+
37
+ # see #scatterStyle
38
+ def scatterStyle=(v)
39
+ Axlsx.validate_scatter_style(v)
40
+ @scatterStyle = v
41
+ end
42
+
43
+ # Serializes the object
44
+ # @param [String] str
45
+ # @return [String]
46
+ 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
65
+ end
66
+ str
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: UTF-8
2
+ module Axlsx
3
+
4
+ # A ScatterSeries defines the x and y position of data in the chart
5
+ # @note The recommended way to manage series is to use Chart#add_series
6
+ # @see Worksheet#add_chart
7
+ # @see Chart#add_series
8
+ # @see examples/example.rb
9
+ class ScatterSeries < Series
10
+
11
+ # The x data for this series.
12
+ # @return [NamedAxisData]
13
+ attr_reader :xData
14
+
15
+ # The y data for this series.
16
+ # @return [NamedAxisData]
17
+ attr_reader :yData
18
+
19
+ # Creates a new ScatterSeries
20
+ def initialize(chart, options={})
21
+ @xData, @yData = nil
22
+ super(chart, options)
23
+
24
+ @xData = NamedAxisData.new("xVal", options[:xData]) unless options[:xData].nil?
25
+ @yData = NamedAxisData.new("yVal", options[:yData]) unless options[:yData].nil?
26
+ end
27
+
28
+ # Serializes the object
29
+ # @param [String] str
30
+ # @return [String]
31
+ def to_xml_string(str = '')
32
+ super(str) do |inner_str|
33
+ @xData.to_xml_string(inner_str) unless @xData.nil?
34
+ @yData.to_xml_string(inner_str) unless @yData.nil?
35
+ end
36
+ str
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  #A SerAxis object defines a series axis
3
4
  class SerAxis < Axis
@@ -21,7 +22,7 @@ module Axlsx
21
22
  def initialize(axId, crossAx, options={})
22
23
  @tickLblSkip, @tickMarkSkip = nil, nil
23
24
  super(axId, crossAx, options)
24
- end
25
+ end
25
26
 
26
27
  # @see tickLblSkip
27
28
  def tickLblSkip=(v) Axlsx::validate_unsigned_int(v); @tickLblSkip = v; end
@@ -29,17 +30,17 @@ module Axlsx
29
30
  # @see tickMarkSkip
30
31
  def tickMarkSkip=(v) Axlsx::validate_unsigned_int(v); @tickMarkSkip = v; end
31
32
 
32
- # Serializes the series axis
33
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
33
+ # Serializes the object
34
+ # @param [String] str
34
35
  # @return [String]
35
- def to_xml(xml)
36
- xml[:c].serAx {
37
- super(xml)
38
- xml[:c].tickLblSkip :val=>@tickLblSkip unless @tickLblSkip.nil?
39
- xml[:c].tickMarkSkip :val=>@tickMarkSkip unless @tickMarkSkip.nil?
40
- }
36
+ def to_xml_string(str = '')
37
+ str << '<c:serAx>'
38
+ super(str)
39
+ str << '<c:tickLblSkip val="' << @tickLblSkip.to_s << '"/>' unless @tickLblSkip.nil?
40
+ str << '<c:tickMarkSkip val="' << @tickMarkSkip.to_s << '"/>' unless @tickMarkSkip.nil?
41
+ str << '</c:serAx>'
41
42
  end
42
43
  end
43
-
44
+
44
45
 
45
46
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # A Series defines the common series attributes and is the super class for all concrete series types.
3
4
  # @note The recommended way to manage series is to use Chart#add_series
@@ -24,7 +25,7 @@ module Axlsx
24
25
  options.each do |o|
25
26
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
26
27
  end
27
- end
28
+ end
28
29
 
29
30
  # The index of this series in the chart's series.
30
31
  # @return [Integer]
@@ -43,27 +44,27 @@ module Axlsx
43
44
  def order=(v) Axlsx::validate_unsigned_int(v); @order = v; end
44
45
 
45
46
  # @see title
46
- def title=(v)
47
+ def title=(v)
47
48
  v = SeriesTitle.new(v) if v.is_a?(String) || v.is_a?(Cell)
48
49
  DataTypeValidator.validate "#{self.class}.title", SeriesTitle, v
49
50
  @title = v
50
51
  end
51
-
52
- private
53
-
52
+
53
+ private
54
+
54
55
  # assigns the chart for this series
55
- def chart=(v) DataTypeValidator.validate "Series.chart", Chart, v; @chart = v; end
56
+ def chart=(v) DataTypeValidator.validate "Series.chart", Chart, v; @chart = v; end
56
57
 
57
- # Serializes the series
58
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
58
+ # Serializes the object
59
+ # @param [String] str
59
60
  # @return [String]
60
- def to_xml(xml)
61
- xml.ser {
62
- xml.idx :val=>index
63
- xml.order :val=>order || index
64
- title.to_xml(xml) unless title.nil?
65
- yield xml if block_given?
66
- }
61
+ def to_xml_string(str = '')
62
+ str << '<c:ser>'
63
+ str << '<c:idx val="' << index.to_s << '"/>'
64
+ str << '<c:order val="' << (order || index).to_s << '"/>'
65
+ title.to_xml_string(str) unless title.nil?
66
+ yield str if block_given?
67
+ str << '</c:ser>'
67
68
  end
68
69
 
69
70
  end
@@ -1,22 +1,23 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # A series title is a Title with a slightly different serialization than chart titles.
3
4
  class SeriesTitle < Title
4
5
 
5
- # Serializes the series title
6
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
6
+ # Serializes the object
7
+ # @param [String] str
7
8
  # @return [String]
8
- def to_xml(xml)
9
- xml[:c].tx {
10
- xml[:c].strRef {
11
- xml[:c].f Axlsx::cell_range([@cell])
12
- xml[:c].strCache {
13
- xml[:c].ptCount :val=>1
14
- xml[:c].pt(:idx=>0) {
15
- xml[:c].v @text
16
- }
17
- }
18
- }
19
- }
9
+ def to_xml_string(str = '')
10
+ str << '<c:tx>'
11
+ str << '<c:strRef>'
12
+ str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
13
+ str << '<c:strCache>'
14
+ str << '<c:ptCount val="1"/>'
15
+ str << '<c:pt idx="0">'
16
+ str << '<c:v>' << @text << '</c:v>'
17
+ str << '</c:pt>'
18
+ str << '</c:strCache>'
19
+ str << '</c:strRef>'
20
+ str << '</c:tx>'
20
21
  end
21
22
  end
22
23
  end
@@ -1,7 +1,8 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # A Title stores information about the title of a chart
3
4
  class Title
4
-
5
+
5
6
  # The text to be shown. Setting this property directly with a string will remove the cell reference.
6
7
  # @return [String]
7
8
  attr_reader :text
@@ -16,9 +17,9 @@ module Axlsx
16
17
  self.cell = title if title.is_a?(Cell)
17
18
  self.text = title.to_s unless title.is_a?(Cell)
18
19
  end
19
-
20
+
20
21
  # @see text
21
- def text=(v)
22
+ def text=(v)
22
23
  DataTypeValidator.validate 'Title.text', String, v
23
24
  @text = v
24
25
  @cell = nil
@@ -29,7 +30,7 @@ module Axlsx
29
30
  def cell=(v)
30
31
  DataTypeValidator.validate 'Title.text', Cell, v
31
32
  @cell = v
32
- @text = v.value.to_s
33
+ @text = v.value.to_s
33
34
  v
34
35
  end
35
36
 
@@ -37,29 +38,29 @@ module Axlsx
37
38
  #def layout=(v) DataTypeValidator.validate 'Title.layout', Layout, v; @layout = v; end
38
39
  #def overlay=(v) Axlsx::validate_boolean v; @overlay=v; end
39
40
  #def spPr=(v) DataTypeValidator.validate 'Title.spPr', SpPr, v; @spPr = v; end
40
-
41
- # Serializes the chart title
42
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
41
+
42
+ # Serializes the object
43
+ # @param [String] str
43
44
  # @return [String]
44
- def to_xml(xml)
45
- xml[:c].title {
46
- unless @text.empty?
47
- xml[:c].tx {
48
- xml[:c].strRef {
49
- xml[:c].f Axlsx::cell_range([@cell])
50
- xml[:c].strCache {
51
- xml[:c].ptCount :val=>1
52
- xml[:c].pt(:idx=>0) {
53
- xml[:c].v @text
54
- }
55
- }
56
- }
57
- }
58
- end
59
- xml[:c].layout
60
- xml[:c].overlay :val=>0
61
- }
45
+ def to_xml_string(str = '')
46
+ str << '<c:title>'
47
+ unless @text.empty?
48
+ str << '<c:tx>'
49
+ str << '<c:strRef>'
50
+ str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
51
+ str << '<c:strCache>'
52
+ str << '<c:ptCount val="1"/>'
53
+ str << '<c:pt idx="0">'
54
+ str << '<c:v>' << @text << '</c:v>'
55
+ str << '</c:pt>'
56
+ str << '</c:strCache>'
57
+ str << '</c:strRef>'
58
+ str << '</c:tx>'
59
+ end
60
+ str << '<c:layout/>'
61
+ str << '<c:overlay val="0"/>'
62
+ str << '</c:title>'
62
63
  end
63
-
64
+
64
65
  end
65
66
  end