axlsx 1.0.17 → 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 (167) hide show
  1. data/CHANGELOG.md +11 -3
  2. data/README.md +159 -51
  3. data/examples/example.csv +1000 -0
  4. data/examples/example.rb +255 -150
  5. data/examples/example.xlsx +0 -0
  6. data/examples/example_streamed.xlsx +0 -0
  7. data/examples/no-use_autowidth.xlsx +0 -0
  8. data/examples/shared_strings_example.xlsx +0 -0
  9. data/lib/axlsx/content_type/content_type.rb +12 -12
  10. data/lib/axlsx/content_type/default.rb +9 -6
  11. data/lib/axlsx/content_type/override.rb +12 -8
  12. data/lib/axlsx/doc_props/app.rb +37 -40
  13. data/lib/axlsx/doc_props/core.rb +12 -17
  14. data/lib/axlsx/drawing/axis.rb +38 -19
  15. data/lib/axlsx/drawing/bar_3D_chart.rb +33 -32
  16. data/lib/axlsx/drawing/bar_series.rb +13 -14
  17. data/lib/axlsx/drawing/cat_axis.rb +15 -14
  18. data/lib/axlsx/drawing/cat_axis_data.rb +16 -18
  19. data/lib/axlsx/drawing/chart.rb +39 -40
  20. data/lib/axlsx/drawing/drawing.rb +15 -12
  21. data/lib/axlsx/drawing/graphic_frame.rb +21 -21
  22. data/lib/axlsx/drawing/hyperlink.rb +12 -11
  23. data/lib/axlsx/drawing/line_3D_chart.rb +30 -28
  24. data/lib/axlsx/drawing/line_series.rb +11 -11
  25. data/lib/axlsx/drawing/marker.rb +10 -8
  26. data/lib/axlsx/drawing/named_axis_data.rb +36 -0
  27. data/lib/axlsx/drawing/one_cell_anchor.rb +17 -16
  28. data/lib/axlsx/drawing/pic.rb +25 -37
  29. data/lib/axlsx/drawing/picture_locking.rb +21 -18
  30. data/lib/axlsx/drawing/pie_3D_chart.rb +10 -8
  31. data/lib/axlsx/drawing/pie_series.rb +15 -12
  32. data/lib/axlsx/drawing/scaling.rb +10 -10
  33. data/lib/axlsx/drawing/scatter_chart.rb +69 -0
  34. data/lib/axlsx/drawing/scatter_series.rb +39 -0
  35. data/lib/axlsx/drawing/ser_axis.rb +10 -10
  36. data/lib/axlsx/drawing/series.rb +15 -15
  37. data/lib/axlsx/drawing/series_title.rb +14 -14
  38. data/lib/axlsx/drawing/title.rb +26 -26
  39. data/lib/axlsx/drawing/two_cell_anchor.rb +18 -20
  40. data/lib/axlsx/drawing/val_axis.rb +8 -7
  41. data/lib/axlsx/drawing/val_axis_data.rb +17 -17
  42. data/lib/axlsx/drawing/view_3D.rb +22 -20
  43. data/lib/axlsx/package.rb +60 -43
  44. data/lib/axlsx/rels/relationship.rb +11 -8
  45. data/lib/axlsx/rels/relationships.rb +7 -1
  46. data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
  47. data/lib/axlsx/stylesheet/border.rb +27 -23
  48. data/lib/axlsx/stylesheet/border_pr.rb +16 -15
  49. data/lib/axlsx/stylesheet/cell_alignment.rb +23 -21
  50. data/lib/axlsx/stylesheet/cell_protection.rb +10 -7
  51. data/lib/axlsx/stylesheet/cell_style.rb +8 -5
  52. data/lib/axlsx/stylesheet/color.rb +20 -14
  53. data/lib/axlsx/stylesheet/fill.rb +7 -5
  54. data/lib/axlsx/stylesheet/font.rb +21 -14
  55. data/lib/axlsx/stylesheet/gradient_fill.rb +19 -16
  56. data/lib/axlsx/stylesheet/gradient_stop.rb +9 -5
  57. data/lib/axlsx/stylesheet/num_fmt.rb +12 -6
  58. data/lib/axlsx/stylesheet/pattern_fill.rb +25 -10
  59. data/lib/axlsx/stylesheet/styles.rb +47 -35
  60. data/lib/axlsx/stylesheet/table_style.rb +9 -4
  61. data/lib/axlsx/stylesheet/table_style_element.rb +10 -7
  62. data/lib/axlsx/stylesheet/table_styles.rb +11 -8
  63. data/lib/axlsx/stylesheet/xf.rb +29 -25
  64. data/lib/axlsx/util/constants.rb +20 -14
  65. data/lib/axlsx/util/simple_typed_list.rb +18 -9
  66. data/lib/axlsx/util/validators.rb +13 -6
  67. data/lib/axlsx/version.rb +1 -1
  68. data/lib/axlsx/workbook/shared_strings_table.rb +19 -21
  69. data/lib/axlsx/workbook/workbook.rb +58 -34
  70. data/lib/axlsx/workbook/worksheet/cell.rb +149 -132
  71. data/lib/axlsx/workbook/worksheet/col.rb +114 -0
  72. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  73. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
  74. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
  75. data/lib/axlsx/workbook/worksheet/row.rb +40 -23
  76. data/lib/axlsx/workbook/worksheet/table.rb +96 -0
  77. data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
  78. data/lib/axlsx/workbook/worksheet/worksheet.rb +243 -127
  79. data/lib/axlsx.rb +30 -9
  80. data/lib/schema/dc.xsd +5 -5
  81. data/lib/schema/dcmitype.xsd +5 -3
  82. data/lib/schema/dcterms.xsd +15 -15
  83. data/lib/schema/opc-coreProperties.xsd +6 -2
  84. data/lib/schema/xml.xsd +7 -8
  85. data/test/#benchmark.txt# +7 -0
  86. data/test/#tc_helper.rb# +3 -0
  87. data/test/benchmark.rb +81 -0
  88. data/test/benchmark.rb~ +0 -0
  89. data/test/benchmark.txt +6 -0
  90. data/test/benchmark.txt~ +6 -0
  91. data/test/content_type/tc_content_type.rb +30 -32
  92. data/test/content_type/tc_default.rb +8 -23
  93. data/test/content_type/tc_override.rb +7 -21
  94. data/test/doc_props/tc_app.rb +2 -8
  95. data/test/doc_props/tc_core.rb +6 -7
  96. data/test/drawing/tc_axis.rb +7 -3
  97. data/test/drawing/tc_bar_3D_chart.rb +6 -7
  98. data/test/drawing/tc_bar_series.rb +4 -5
  99. data/test/drawing/tc_cat_axis.rb +2 -3
  100. data/test/drawing/tc_cat_axis_data.rb +2 -3
  101. data/test/drawing/tc_chart.rb +13 -14
  102. data/test/drawing/tc_drawing.rb +7 -8
  103. data/test/drawing/tc_graphic_frame.rb +3 -4
  104. data/test/drawing/tc_hyperlink.rb +2 -3
  105. data/test/drawing/tc_line_3d_chart.rb +5 -6
  106. data/test/drawing/tc_line_series.rb +3 -4
  107. data/test/drawing/tc_marker.rb +3 -4
  108. data/test/drawing/tc_one_cell_anchor.rb +6 -7
  109. data/test/drawing/tc_pic.rb +8 -9
  110. data/test/drawing/tc_picture_locking.rb +2 -3
  111. data/test/drawing/tc_pie_3D_chart.rb +5 -6
  112. data/test/drawing/tc_pie_series.rb +4 -5
  113. data/test/drawing/tc_scaling.rb +3 -4
  114. data/test/drawing/tc_scatter_chart.rb +43 -0
  115. data/test/drawing/tc_scatter_series.rb +20 -0
  116. data/test/drawing/tc_ser_axis.rb +2 -3
  117. data/test/drawing/tc_series.rb +4 -5
  118. data/test/drawing/tc_series_title.rb +4 -5
  119. data/test/drawing/tc_title.rb +4 -5
  120. data/test/drawing/tc_two_cell_anchor.rb +4 -5
  121. data/test/drawing/tc_val_axis.rb +2 -3
  122. data/test/drawing/tc_val_axis_data.rb +2 -3
  123. data/test/drawing/tc_view_3D.rb +6 -7
  124. data/test/example.csv +1000 -0
  125. data/test/example.xlsx +0 -0
  126. data/test/example_streamed.xlsx +0 -0
  127. data/test/profile.rb +33 -0
  128. data/test/rels/tc_relationship.rb +5 -6
  129. data/test/rels/tc_relationships.rb +4 -5
  130. data/test/stylesheet/tc_border.rb +3 -4
  131. data/test/stylesheet/tc_border_pr.rb +3 -4
  132. data/test/stylesheet/tc_cell_alignment.rb +10 -6
  133. data/test/stylesheet/tc_cell_protection.rb +2 -3
  134. data/test/stylesheet/tc_cell_style.rb +2 -3
  135. data/test/stylesheet/tc_color.rb +2 -3
  136. data/test/stylesheet/tc_fill.rb +1 -2
  137. data/test/stylesheet/tc_font.rb +12 -5
  138. data/test/stylesheet/tc_gradient_fill.rb +1 -2
  139. data/test/stylesheet/tc_gradient_stop.rb +1 -2
  140. data/test/stylesheet/tc_num_fmt.rb +1 -2
  141. data/test/stylesheet/tc_pattern_fill.rb +3 -4
  142. data/test/stylesheet/tc_styles.rb +16 -6
  143. data/test/stylesheet/tc_table_style.rb +2 -3
  144. data/test/stylesheet/tc_table_style_element.rb +2 -3
  145. data/test/stylesheet/tc_table_styles.rb +3 -4
  146. data/test/stylesheet/tc_xf.rb +16 -17
  147. data/test/tc_axlsx.rb +39 -0
  148. data/test/tc_axlsx.rb~ +0 -0
  149. data/test/tc_helper.rb +3 -0
  150. data/test/tc_helper.rb~ +3 -0
  151. data/test/tc_package.rb +13 -10
  152. data/test/util/tc_simple_typed_list.rb +8 -9
  153. data/test/util/tc_validators.rb +7 -8
  154. data/test/workbook/tc_shared_strings_table.rb +5 -6
  155. data/test/workbook/tc_workbook.rb +24 -6
  156. data/test/workbook/worksheet/table/tc_table.rb +71 -0
  157. data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
  158. data/test/workbook/worksheet/tc_cell.rb +62 -18
  159. data/test/workbook/worksheet/tc_col.rb +59 -0
  160. data/test/workbook/worksheet/tc_col.rb~ +10 -0
  161. data/test/workbook/worksheet/tc_date_time_converter.rb +126 -0
  162. data/test/workbook/worksheet/tc_page_margins.rb +97 -0
  163. data/test/workbook/worksheet/tc_row.rb +54 -4
  164. data/test/workbook/worksheet/tc_worksheet.rb +177 -34
  165. metadata +69 -41
  166. data/test/drawing/tc_hyperlink.rb~ +0 -71
  167. data/test/workbook/tc_shared_strings_table.rb~ +0 -8
@@ -28,7 +28,7 @@ module Axlsx
28
28
  # @return [Title]
29
29
  attr_reader :title
30
30
 
31
- # The style for the chart.
31
+ # The style for the chart.
32
32
  # see ECMA Part 1 §21.2.2.196
33
33
  # @return [Integer]
34
34
  attr_reader :style
@@ -36,13 +36,14 @@ module Axlsx
36
36
  # Show the legend in the chart
37
37
  # @return [Boolean]
38
38
  attr_reader :show_legend
39
-
39
+
40
40
  # Creates a new chart object
41
41
  # @param [GraphicalFrame] frame The frame that holds this chart.
42
42
  # @option options [Cell, String] title
43
43
  # @option options [Boolean] show_legend
44
44
  def initialize(frame, options={})
45
45
  @style = 2
46
+ @view3D = nil
46
47
  @graphic_frame=frame
47
48
  @graphic_frame.anchor.drawing.worksheet.workbook.charts << self
48
49
  @series = SimpleTypedList.new Series
@@ -52,8 +53,8 @@ module Axlsx
52
53
  options.each do |o|
53
54
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
54
55
  end
55
- start_at *options[:start_at] if options[:start_at]
56
- end_at *options[:end_at] if options[:start_at]
56
+ start_at(*options[:start_at]) if options[:start_at]
57
+ end_at(*options[:end_at]) if options[:start_at]
57
58
  yield self if block_given?
58
59
  end
59
60
 
@@ -72,7 +73,7 @@ module Axlsx
72
73
  # The title object for the chart.
73
74
  # @param [String, Cell] v
74
75
  # @return [Title]
75
- def title=(v)
76
+ def title=(v)
76
77
  DataTypeValidator.validate "#{self.class}.title", [String, Cell], v
77
78
  if v.is_a?(String)
78
79
  @title.text = v
@@ -80,14 +81,14 @@ module Axlsx
80
81
  @title.cell = v
81
82
  end
82
83
  end
83
-
84
+
84
85
  # Show the legend in the chart
85
86
  # @param [Boolean] v
86
87
  # @return [Boolean]
87
88
  def show_legend=(v) Axlsx::validate_boolean(v); @show_legend = v; end
88
89
 
89
90
 
90
- # The style for the chart.
91
+ # The style for the chart.
91
92
  # see ECMA Part 1 §21.2.2.196
92
93
  # @param [Integer] v must be between 1 and 48
93
94
  def style=(v) DataTypeValidator.validate "Chart.style", Integer, v, lambda { |arg| arg >= 1 && arg <= 48 }; @style = v; end
@@ -112,40 +113,38 @@ module Axlsx
112
113
  @series.last
113
114
  end
114
115
 
115
- # Chart Serialization
116
- # serializes the chart
117
- def to_xml
118
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
119
- xml.send('c:chartSpace', :'xmlns:c' => XML_NS_C, :'xmlns:a' => XML_NS_A) {
120
- xml[:c].date1904 :val => Axlsx::Workbook.date1904
121
- xml[:c].style :val=>style
122
- xml[:c].chart {
123
- @title.to_xml(xml)
124
- xml.autoTitleDeleted :val=>0
125
- @view3D.to_xml(xml) unless @view3D.nil?
126
-
127
- xml.floor { xml.thickness(:val=>0) }
128
- xml.sideWall { xml.thickness(:val=>0) }
129
- xml.backWall { xml.thickness(:val=>0) }
130
- xml.plotArea {
131
- xml.layout
132
- yield xml if block_given?
133
- }
134
- if @show_legend
135
- xml.legend {
136
- xml.legendPos :val => "r"
137
- xml.layout
138
- xml.overlay :val => 0
139
- }
140
- end
141
- xml.plotVisOnly :val => 1
142
- xml.dispBlanksAs :val => :zero
143
- xml.showDLblsOverMax :val => 1
144
- }
145
-
146
- }
116
+ # Serializes the object
117
+ # @param [String] str
118
+ # @return [String]
119
+ def to_xml_string(str = '')
120
+ str << '<?xml version="1.0" encoding="UTF-8"?>'
121
+ str << '<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '">'
122
+ str << '<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>'
123
+ str << '<c:style val="' << style.to_s << '"/>'
124
+ str << '<c:chart>'
125
+ @title.to_xml_string str
126
+ # do these need the c: namespace as well???
127
+ str << '<c:autoTitleDeleted val="0"/>'
128
+ @view3D.to_xml_string(str) if @view3D
129
+ str << '<c:floor><c:thickness val="0"/></c:floor>'
130
+ str << '<c:sideWall><c:thickness val="0"/></c:sideWall>'
131
+ str << '<c:backWall><c:thickness val="0"/></c:backWall>'
132
+ str << '<c:plotArea>'
133
+ str << '<c:layout/>'
134
+ yield str if block_given?
135
+ str << '</c:plotArea>'
136
+ if @show_legend
137
+ str << '<c:legend>'
138
+ str << '<c:legendPos val="r"/>'
139
+ str << '<c:layout/>'
140
+ str << '<c:overlay val="0"/>'
141
+ str << '</c:legend>'
147
142
  end
148
- builder.to_xml(:save_with => 0)
143
+ str << '<c:plotVisOnly val="1"/>'
144
+ str << '<c:dispBlanksAs val="zero"/>'
145
+ str << '<c:showDLblsOverMax val="1"/>'
146
+ str << '</c:chart>'
147
+ str << '</c:chartSpace>'
149
148
  end
150
149
 
151
150
  # This is a short cut method to set the start anchor position
@@ -4,8 +4,9 @@ module Axlsx
4
4
  require 'axlsx/drawing/series_title.rb'
5
5
  require 'axlsx/drawing/series.rb'
6
6
  require 'axlsx/drawing/pie_series.rb'
7
- require 'axlsx/drawing/bar_series.rb'
8
- require 'axlsx/drawing/line_series.rb'
7
+ require 'axlsx/drawing/bar_series.rb'
8
+ require 'axlsx/drawing/line_series.rb'
9
+ require 'axlsx/drawing/scatter_series.rb'
9
10
 
10
11
  require 'axlsx/drawing/scaling.rb'
11
12
  require 'axlsx/drawing/axis.rb'
@@ -15,9 +16,10 @@ module Axlsx
15
16
 
16
17
  require 'axlsx/drawing/cat_axis_data.rb'
17
18
  require 'axlsx/drawing/val_axis_data.rb'
19
+ require 'axlsx/drawing/named_axis_data.rb'
18
20
 
19
21
  require 'axlsx/drawing/marker.rb'
20
-
22
+
21
23
  require 'axlsx/drawing/one_cell_anchor.rb'
22
24
  require 'axlsx/drawing/two_cell_anchor.rb'
23
25
  require 'axlsx/drawing/graphic_frame.rb'
@@ -27,6 +29,7 @@ module Axlsx
27
29
  require 'axlsx/drawing/pie_3D_chart.rb'
28
30
  require 'axlsx/drawing/bar_3D_chart.rb'
29
31
  require 'axlsx/drawing/line_3D_chart.rb'
32
+ require 'axlsx/drawing/scatter_chart.rb'
30
33
 
31
34
  require 'axlsx/drawing/picture_locking.rb'
32
35
  require 'axlsx/drawing/pic.rb'
@@ -43,7 +46,7 @@ module Axlsx
43
46
  # The worksheet that owns the drawing
44
47
  # @return [Worksheet]
45
48
  attr_reader :worksheet
46
-
49
+
47
50
  # A collection of anchors for this drawing
48
51
  # only TwoCellAnchors are supported in this version
49
52
  # @return [SimpleTypedList]
@@ -135,15 +138,15 @@ module Axlsx
135
138
  r
136
139
  end
137
140
 
138
- # Serializes the drawing
141
+ # Serializes the object
142
+ # @param [String] str
139
143
  # @return [String]
140
- def to_xml
141
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
142
- xml.send('xdr:wsDr', :'xmlns:xdr'=>XML_NS_XDR, :'xmlns:a'=>XML_NS_A, :'xmlns:c'=>XML_NS_C) {
143
- anchors.each {|anchor| anchor.to_xml(xml) }
144
- }
145
- end
146
- builder.to_xml(:save_with => 0)
144
+ 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 << '">'
147
+ anchors.each { |anchor| anchor.to_xml_string(str) }
148
+ str << '</xdr:wsDr>'
147
149
  end
150
+
148
151
  end
149
152
  end
@@ -17,37 +17,37 @@ module Axlsx
17
17
  # @param [TwoCellAnchor] anchor
18
18
  # @param [Class] chart_type
19
19
  def initialize(anchor, chart_type, options)
20
- DataTypeValidator.validate "Drawing.chart_type", Chart, chart_type
20
+ DataTypeValidator.validate "Drawing.chart_type", Chart, chart_type
21
21
  @anchor = anchor
22
22
  @chart = chart_type.new(self, options)
23
23
  end
24
24
 
25
25
  # The relationship id for this graphic
26
26
  # @return [String]
27
- def rId
27
+ def rId
28
28
  "rId#{@anchor.index+1}"
29
29
  end
30
30
 
31
- # Serializes the graphic frame
32
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
31
+ # Serializes the object
32
+ # @param [String] str
33
33
  # @return [String]
34
- def to_xml(xml)
35
- xml.graphicFrame {
36
- xml.nvGraphicFramePr {
37
- xml.cNvPr :id=>2, :name=>chart.title
38
- xml.cNvGraphicFramePr
39
- }
40
- xml.xfrm {
41
- xml[:a].off(:x=>0, :y=>0)
42
- xml[:a].ext :cx=>0, :cy=>0
43
- }
44
- xml[:a].graphic {
45
- xml.graphicData(:uri=>XML_NS_C) {
46
- xml[:c].chart :'xmlns:c'=>XML_NS_C, :'xmlns:r'=>XML_NS_R, :'r:id'=>rId
47
- }
48
- }
49
- }
50
-
34
+ def to_xml_string(str = '')
35
+ str << '<xdr:graphicFrame>'
36
+ str << '<xdr:nvGraphicFramePr>'
37
+ str << '<xdr:cNvPr id="2" name="' << chart.title.text << '"/>'
38
+ str << '<xdr:cNvGraphicFramePr/>'
39
+ str << '</xdr:nvGraphicFramePr>'
40
+ str << '<xdr:xfrm>'
41
+ str << '<a:off x="0" y="0"/>'
42
+ str << '<a:ext cx="0" cy="0"/>'
43
+ str << '</xdr:xfrm>'
44
+ str << '<a:graphic>'
45
+ str << '<a:graphicData uri="' << XML_NS_C << '">'
46
+ str << '<c:chart xmlns:c="' << XML_NS_C << '" xmlns:r="' << XML_NS_R << '" r:id="' << rId.to_s << '"/>'
47
+ str << '</a:graphicData>'
48
+ str << '</a:graphic>'
49
+ str << '</xdr:graphicFrame>'
51
50
  end
51
+
52
52
  end
53
53
  end
@@ -31,12 +31,12 @@ module Axlsx
31
31
  # indicates that the link has already been clicked.
32
32
  # @return [Boolean]
33
33
  attr_reader :highlightClick
34
-
34
+
35
35
  # @see highlightClick
36
36
  # @param [Boolean] v The value to assign
37
37
  def highlightClick=(v) Axlsx::validate_boolean(v); @highlightClick = v end
38
38
 
39
- # From the specs: Specifies whether to add this URI to the history when navigating to it. This allows for the viewing of this presentation without the storing of history information on the viewing machine. If this attribute is omitted, then a value of 1 or true is assumed.
39
+ # From the specs: Specifies whether to add this URI to the history when navigating to it. This allows for the viewing of this presentation without the storing of history information on the viewing machine. If this attribute is omitted, then a value of 1 or true is assumed.
40
40
  # @return [Boolean]
41
41
  attr_reader :history
42
42
 
@@ -52,12 +52,12 @@ module Axlsx
52
52
  # @return [String]
53
53
  attr_accessor :tooltip
54
54
 
55
- #Creates a hyperlink object
55
+ #Creates a hyperlink object
56
56
  # parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent
57
57
  # @param [Pic] parent
58
58
  # @option options [String] tooltip message shown when hyperlinked object is hovered over with mouse.
59
59
  # @option options [String] tgtFrame Target frame for opening hyperlink
60
- # @option options [String] invalidUrl supposedly use to store the href when we know it is an invalid resource.
60
+ # @option options [String] invalidUrl supposedly use to store the href when we know it is an invalid resource.
61
61
  # @option options [String] href the target resource this hyperlink links to.
62
62
  # @option options [String] action A string that can be used to perform specific actions. For excel please see this reference: http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
63
63
  # @option options [Boolean] endSnd terminate any sound events when processing this link
@@ -70,22 +70,23 @@ module Axlsx
70
70
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
71
71
  end
72
72
  yield self if block_given?
73
-
74
- end
75
73
 
74
+ end
76
75
 
77
- # Serializes the hyperlink
78
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
76
+ # Serializes the object
77
+ # @param [String] str
79
78
  # @return [String]
80
- def to_xml(xml)
79
+ def to_xml_string(str = '')
81
80
  h = self.instance_values.merge({:'r:id' => "rId#{id}", :'xmlns:r' => XML_NS_R })
82
81
  h.delete('href')
83
82
  h.delete('parent')
84
- xml[:a].hlinkClick h
83
+ str << '<a:hlinkClick '
84
+ str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
85
+ str << '/>'
85
86
  end
86
87
 
87
88
  private
88
- # The relational ID for this hyperlink
89
+ # The relational ID for this hyperlink
89
90
  # @return [Integer]
90
91
  def id
91
92
  @parent.anchor.drawing.charts.size + @parent.anchor.drawing.images.size + @parent.anchor.drawing.hyperlinks.index(self) + 1
@@ -44,11 +44,11 @@ module Axlsx
44
44
 
45
45
  # validation regex for gap amount percent
46
46
  GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
47
-
47
+
48
48
  # Creates a new line chart object
49
49
  # @param [GraphicFrame] frame The workbook that owns this chart.
50
50
  # @option options [Cell, String] title
51
- # @option options [Boolean] show_legend
51
+ # @option options [Boolean] show_legend
52
52
  # @option options [Symbol] grouping
53
53
  # @option options [String] gapDepth
54
54
  # @option options [Integer] rotX
@@ -68,7 +68,7 @@ module Axlsx
68
68
  @catAxis = CatAxis.new(@catAxId, @valAxId)
69
69
  @valAxis = ValAxis.new(@valAxId, @catAxId)
70
70
  @serAxis = SerAxis.new(@serAxId, @valAxId)
71
- super(frame, options)
71
+ super(frame, options)
72
72
  @series_type = LineSeries
73
73
  @view3D = View3D.new({:perspective=>30}.merge(options))
74
74
  end
@@ -85,31 +85,33 @@ module Axlsx
85
85
  @gapDepth=(v)
86
86
  end
87
87
 
88
- # Serializes the bar chart
88
+ # Serializes the object
89
+ # @param [String] str
89
90
  # @return [String]
90
- def to_xml
91
- super() do |xml|
92
- xml.line3DChart {
93
- xml.grouping :val=>grouping
94
- xml.varyColors :val=>1
95
- @series.each { |ser| ser.to_xml(xml) }
96
- xml.dLbls {
97
- xml.showLegendKey :val=>0
98
- xml.showVal :val=>0
99
- xml.showCatName :val=>0
100
- xml.showSerName :val=>0
101
- xml.showPercent :val=>0
102
- xml.showBubbleSize :val=>0
103
- }
104
- xml.gapDepth :val=>@gapDepth unless @gapDepth.nil?
105
- xml.axId :val=>@catAxId
106
- xml.axId :val=>@valAxId
107
- xml.axId :val=>@serAxId
108
- }
109
- @catAxis.to_xml(xml)
110
- @valAxis.to_xml(xml)
111
- @serAxis.to_xml(xml)
91
+ def to_xml_string(str = '')
92
+ super(str) do |str_inner|
93
+ str_inner << '<c:line3DChart>'
94
+ str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
95
+ str_inner << '<c:varyColors val="1"/>'
96
+ @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>'
105
+ str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
106
+ str_inner << '<c:axId val="' << @catAxId.to_s << '"/>'
107
+ str_inner << '<c:axId val="' << @valAxId.to_s << '"/>'
108
+ str_inner << '<c:axId val="' << @serAxId.to_s << '"/>'
109
+ str_inner << '</c:line3DChart>'
110
+ @catAxis.to_xml_string str_inner
111
+ @valAxis.to_xml_string str_inner
112
+ @serAxis.to_xml_string str_inner
112
113
  end
113
- end
114
- end
114
+ end
115
+
116
+ end
115
117
  end
@@ -5,8 +5,8 @@ module Axlsx
5
5
  # @see Worksheet#add_chart
6
6
  # @see Chart#add_series
7
7
  class LineSeries < Series
8
-
9
- # The data for this series.
8
+
9
+ # The data for this series.
10
10
  # @return [ValAxisData]
11
11
  attr_reader :data
12
12
 
@@ -23,19 +23,19 @@ module Axlsx
23
23
  super(chart, options)
24
24
  @labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
25
25
  @data = ValAxisData.new(options[:data]) unless options[:data].nil?
26
- end
26
+ end
27
27
 
28
- # Serializes the series
29
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
28
+ # Serializes the object
29
+ # @param [String] str
30
30
  # @return [String]
31
- def to_xml(xml)
32
- super(xml) do |xml_inner|
33
- @labels.to_xml(xml_inner) unless @labels.nil?
34
- @data.to_xml(xml_inner) unless @data.nil?
35
- end
31
+ def to_xml_string(str = '')
32
+ super(str) do
33
+ @labels.to_xml_string(str) unless @labels.nil?
34
+ @data.to_xml_string(str) unless @data.nil?
35
+ end
36
36
  end
37
37
 
38
- private
38
+ private
39
39
 
40
40
  # assigns the data for this series
41
41
  def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
@@ -30,9 +30,9 @@ module Axlsx
30
30
  @col, @colOff, @row, @rowOff = 0, 0, 0, 0
31
31
  options.each do |o|
32
32
  self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
33
- end
33
+ end
34
34
  end
35
-
35
+
36
36
  # @see col
37
37
  def col=(v) Axlsx::validate_unsigned_int v; @col = v end
38
38
  # @see colOff
@@ -41,7 +41,7 @@ module Axlsx
41
41
  def row=(v) Axlsx::validate_unsigned_int v; @row = v end
42
42
  # @see rowOff
43
43
  def rowOff=(v) Axlsx::validate_int v; @rowOff = v end
44
-
44
+
45
45
  # shortcut to set the column, row position for this marker
46
46
  # @param col the column for the marker
47
47
  # @param row the row of the marker
@@ -49,14 +49,16 @@ module Axlsx
49
49
  self.col = col
50
50
  self.row = row
51
51
  end
52
- # Serializes the marker
53
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
52
+
53
+ # Serializes the object
54
+ # @param [String] str
54
55
  # @return [String]
55
- def to_xml(xml)
56
+ def to_xml_string(str = '')
56
57
  [:col, :colOff, :row, :rowOff].each do |k|
57
- xml.send(k.to_sym, self.send(k))
58
- end
58
+ str << '<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>'
59
+ end
59
60
  end
61
+
60
62
  end
61
63
 
62
64
  end
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+ # TODO: review cat, val and named access data to extend this and reduce replicated code.
3
+ module Axlsx
4
+ # The ValAxisData class manages the values for a chart value series.
5
+ class NamedAxisData < CatAxisData
6
+
7
+ # creates a new NamedAxisData Object
8
+ # @param [String] name The serialized node name for the axis data object
9
+ # @param [Array] The data to associate with the axis data object
10
+ def initialize(name, data=[])
11
+ super(data)
12
+ @name = name
13
+ end
14
+
15
+ # Serializes the object
16
+ # @param [String] str
17
+ # @return [String]
18
+ def to_xml_string(str = '')
19
+ str << '<c:' << @name.to_s << '>'
20
+ str << '<c:numRef>'
21
+ str << '<c:f>' << Axlsx::cell_range(@list) << '</c:f>'
22
+ str << '<c:numCache>'
23
+ str << '<c:formatCode>General</c:formatCode>'
24
+ str << '<c:ptCount val="' << size.to_s << '"/>'
25
+ each_with_index do |item, index|
26
+ v = item.is_a?(Cell) ? item.value.to_s : item
27
+ str << '<c:pt idx="' << index.to_s << '"><c:v>' << v << '</c:v></c:pt>'
28
+ end
29
+ str << '</c:numCache>'
30
+ str << '</c:numRef>'
31
+ str << '</c:' << @name.to_s << '>'
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -33,15 +33,15 @@ module Axlsx
33
33
  # @param [Drawing] drawing
34
34
  # @option options [Array] start_at the col, row to start at
35
35
  # @option options [Integer] width
36
- # @option options [Integer] height
36
+ # @option options [Integer] height
37
37
  # @option options [String] image_src the file location of the image you will render
38
38
  # @option options [String] name the name attribute for the rendered image
39
- # @option options [String] descr the description of the image rendered
39
+ # @option options [String] descr the description of the image rendered
40
40
  def initialize(drawing, options={})
41
41
  @drawing = drawing
42
42
  @width = 0
43
43
  @height = 0
44
- drawing.anchors << self
44
+ drawing.anchors << self
45
45
  @from = Marker.new
46
46
  options.each do |o|
47
47
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
@@ -61,23 +61,24 @@ module Axlsx
61
61
  @drawing.anchors.index(self)
62
62
  end
63
63
 
64
- # Serializes the anchor
65
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
64
+
65
+ # Serializes the object
66
+ # @param [String] str
66
67
  # @return [String]
67
- def to_xml(xml)
68
- xml[:xdr].oneCellAnchor {
69
- xml.from {
70
- from.to_xml(xml)
71
- }
72
- xml.ext ext
73
- @object.to_xml(xml)
74
- xml.clientData
75
- }
76
- end
68
+ def to_xml_string(str = '')
69
+ str << '<xdr:oneCellAnchor>'
70
+ str << '<xdr:from>'
71
+ from.to_xml_string(str)
72
+ str << '</xdr:from>'
73
+ str << '<xdr:ext cx="' << ext[:cx].to_s << '" cy="' << ext[:cy].to_s << '"/>'
74
+ @object.to_xml_string(str)
75
+ str << '<xdr:clientData/>'
76
+ str << '</xdr:oneCellAnchor>'
77
+ end
77
78
 
78
79
  private
79
80
 
80
- # converts the pixel width and height to EMU units and returns a hash of
81
+ # converts the pixel width and height to EMU units and returns a hash of
81
82
  # !{:cx=>[Integer], :cy=>[Integer]
82
83
  # @return [Hash]
83
84
  def ext