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 Chart is the superclass for specific charts
4
4
  # @note Worksheet#add_chart is the recommended way to create charts for your worksheets.
@@ -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
@@ -1,10 +1,12 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  require 'axlsx/drawing/title.rb'
3
4
  require 'axlsx/drawing/series_title.rb'
4
5
  require 'axlsx/drawing/series.rb'
5
6
  require 'axlsx/drawing/pie_series.rb'
6
- require 'axlsx/drawing/bar_series.rb'
7
- 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'
8
10
 
9
11
  require 'axlsx/drawing/scaling.rb'
10
12
  require 'axlsx/drawing/axis.rb'
@@ -14,9 +16,10 @@ module Axlsx
14
16
 
15
17
  require 'axlsx/drawing/cat_axis_data.rb'
16
18
  require 'axlsx/drawing/val_axis_data.rb'
19
+ require 'axlsx/drawing/named_axis_data.rb'
17
20
 
18
21
  require 'axlsx/drawing/marker.rb'
19
-
22
+
20
23
  require 'axlsx/drawing/one_cell_anchor.rb'
21
24
  require 'axlsx/drawing/two_cell_anchor.rb'
22
25
  require 'axlsx/drawing/graphic_frame.rb'
@@ -26,6 +29,7 @@ module Axlsx
26
29
  require 'axlsx/drawing/pie_3D_chart.rb'
27
30
  require 'axlsx/drawing/bar_3D_chart.rb'
28
31
  require 'axlsx/drawing/line_3D_chart.rb'
32
+ require 'axlsx/drawing/scatter_chart.rb'
29
33
 
30
34
  require 'axlsx/drawing/picture_locking.rb'
31
35
  require 'axlsx/drawing/pic.rb'
@@ -42,7 +46,7 @@ module Axlsx
42
46
  # The worksheet that owns the drawing
43
47
  # @return [Worksheet]
44
48
  attr_reader :worksheet
45
-
49
+
46
50
  # A collection of anchors for this drawing
47
51
  # only TwoCellAnchors are supported in this version
48
52
  # @return [SimpleTypedList]
@@ -134,15 +138,15 @@ module Axlsx
134
138
  r
135
139
  end
136
140
 
137
- # Serializes the drawing
141
+ # Serializes the object
142
+ # @param [String] str
138
143
  # @return [String]
139
- def to_xml
140
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
141
- xml.send('xdr:wsDr', :'xmlns:xdr'=>XML_NS_XDR, :'xmlns:a'=>XML_NS_A, :'xmlns:c'=>XML_NS_C) {
142
- anchors.each {|anchor| anchor.to_xml(xml) }
143
- }
144
- end
145
- 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>'
146
149
  end
150
+
147
151
  end
148
152
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # A graphic frame defines a container for a chart object
3
4
  # @note The recommended way to manage charts is Worksheet#add_chart
@@ -16,37 +17,37 @@ module Axlsx
16
17
  # @param [TwoCellAnchor] anchor
17
18
  # @param [Class] chart_type
18
19
  def initialize(anchor, chart_type, options)
19
- DataTypeValidator.validate "Drawing.chart_type", Chart, chart_type
20
+ DataTypeValidator.validate "Drawing.chart_type", Chart, chart_type
20
21
  @anchor = anchor
21
22
  @chart = chart_type.new(self, options)
22
23
  end
23
24
 
24
25
  # The relationship id for this graphic
25
26
  # @return [String]
26
- def rId
27
+ def rId
27
28
  "rId#{@anchor.index+1}"
28
29
  end
29
30
 
30
- # Serializes the graphic frame
31
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
31
+ # Serializes the object
32
+ # @param [String] str
32
33
  # @return [String]
33
- def to_xml(xml)
34
- xml.graphicFrame {
35
- xml.nvGraphicFramePr {
36
- xml.cNvPr :id=>2, :name=>chart.title
37
- xml.cNvGraphicFramePr
38
- }
39
- xml.xfrm {
40
- xml[:a].off(:x=>0, :y=>0)
41
- xml[:a].ext :cx=>0, :cy=>0
42
- }
43
- xml[:a].graphic {
44
- xml.graphicData(:uri=>XML_NS_C) {
45
- xml[:c].chart :'xmlns:c'=>XML_NS_C, :'xmlns:r'=>XML_NS_R, :'r:id'=>rId
46
- }
47
- }
48
- }
49
-
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>'
50
50
  end
51
+
51
52
  end
52
53
  end
@@ -1,4 +1,4 @@
1
- # -*- coding: utf-8 -*-
1
+ # encoding: UTF-8
2
2
  module Axlsx
3
3
  # a hyperlink object adds an action to an image when clicked so that when the image is clicked the link is fecthed.
4
4
  # @note using the hyperlink option when calling add_image on a drawing object is the recommended way to manage hyperlinks
@@ -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
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
 
3
4
  # The Line3DChart is a three dimentional line chart (who would have guessed?) that you can add to your worksheet.
@@ -43,11 +44,11 @@ module Axlsx
43
44
 
44
45
  # validation regex for gap amount percent
45
46
  GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
46
-
47
+
47
48
  # Creates a new line chart object
48
49
  # @param [GraphicFrame] frame The workbook that owns this chart.
49
50
  # @option options [Cell, String] title
50
- # @option options [Boolean] show_legend
51
+ # @option options [Boolean] show_legend
51
52
  # @option options [Symbol] grouping
52
53
  # @option options [String] gapDepth
53
54
  # @option options [Integer] rotX
@@ -67,7 +68,7 @@ module Axlsx
67
68
  @catAxis = CatAxis.new(@catAxId, @valAxId)
68
69
  @valAxis = ValAxis.new(@valAxId, @catAxId)
69
70
  @serAxis = SerAxis.new(@serAxId, @valAxId)
70
- super(frame, options)
71
+ super(frame, options)
71
72
  @series_type = LineSeries
72
73
  @view3D = View3D.new({:perspective=>30}.merge(options))
73
74
  end
@@ -84,31 +85,33 @@ module Axlsx
84
85
  @gapDepth=(v)
85
86
  end
86
87
 
87
- # Serializes the bar chart
88
+ # Serializes the object
89
+ # @param [String] str
88
90
  # @return [String]
89
- def to_xml
90
- super() do |xml|
91
- xml.line3DChart {
92
- xml.grouping :val=>grouping
93
- xml.varyColors :val=>1
94
- @series.each { |ser| ser.to_xml(xml) }
95
- xml.dLbls {
96
- xml.showLegendKey :val=>0
97
- xml.showVal :val=>0
98
- xml.showCatName :val=>0
99
- xml.showSerName :val=>0
100
- xml.showPercent :val=>0
101
- xml.showBubbleSize :val=>0
102
- }
103
- xml.gapDepth :val=>@gapDepth unless @gapDepth.nil?
104
- xml.axId :val=>@catAxId
105
- xml.axId :val=>@valAxId
106
- xml.axId :val=>@serAxId
107
- }
108
- @catAxis.to_xml(xml)
109
- @valAxis.to_xml(xml)
110
- @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
111
113
  end
112
- end
113
- end
114
+ end
115
+
116
+ end
114
117
  end
@@ -1,11 +1,12 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # A LineSeries defines the title, data and labels for line charts
3
4
  # @note The recommended way to manage series is to use Chart#add_series
4
5
  # @see Worksheet#add_chart
5
6
  # @see Chart#add_series
6
7
  class LineSeries < Series
7
-
8
- # The data for this series.
8
+
9
+ # The data for this series.
9
10
  # @return [ValAxisData]
10
11
  attr_reader :data
11
12
 
@@ -22,19 +23,19 @@ module Axlsx
22
23
  super(chart, options)
23
24
  @labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
24
25
  @data = ValAxisData.new(options[:data]) unless options[:data].nil?
25
- end
26
+ end
26
27
 
27
- # Serializes the series
28
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
28
+ # Serializes the object
29
+ # @param [String] str
29
30
  # @return [String]
30
- def to_xml(xml)
31
- super(xml) do |xml_inner|
32
- @labels.to_xml(xml_inner) unless @labels.nil?
33
- @data.to_xml(xml_inner) unless @data.nil?
34
- 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
35
36
  end
36
37
 
37
- private
38
+ private
38
39
 
39
40
  # assigns the data for this series
40
41
  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 Marker class defines a point in the worksheet that drawing anchors attach to.
3
4
  # @note The recommended way to manage markers is Worksheet#add_chart Markers are created for a two cell anchor based on the :start and :end options.
@@ -29,9 +30,9 @@ module Axlsx
29
30
  @col, @colOff, @row, @rowOff = 0, 0, 0, 0
30
31
  options.each do |o|
31
32
  self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
32
- end
33
+ end
33
34
  end
34
-
35
+
35
36
  # @see col
36
37
  def col=(v) Axlsx::validate_unsigned_int v; @col = v end
37
38
  # @see colOff
@@ -40,7 +41,7 @@ module Axlsx
40
41
  def row=(v) Axlsx::validate_unsigned_int v; @row = v end
41
42
  # @see rowOff
42
43
  def rowOff=(v) Axlsx::validate_int v; @rowOff = v end
43
-
44
+
44
45
  # shortcut to set the column, row position for this marker
45
46
  # @param col the column for the marker
46
47
  # @param row the row of the marker
@@ -48,14 +49,16 @@ module Axlsx
48
49
  self.col = col
49
50
  self.row = row
50
51
  end
51
- # Serializes the marker
52
- # @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
53
55
  # @return [String]
54
- def to_xml(xml)
56
+ def to_xml_string(str = '')
55
57
  [:col, :colOff, :row, :rowOff].each do |k|
56
- xml.send(k.to_sym, self.send(k))
57
- end
58
+ str << '<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>'
59
+ end
58
60
  end
61
+
59
62
  end
60
63
 
61
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
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # This class details a single cell anchor for drawings.
3
4
  # @note The recommended way to manage drawings, images and charts is Worksheet#add_chart or Worksheet#add_image.
@@ -32,15 +33,15 @@ module Axlsx
32
33
  # @param [Drawing] drawing
33
34
  # @option options [Array] start_at the col, row to start at
34
35
  # @option options [Integer] width
35
- # @option options [Integer] height
36
+ # @option options [Integer] height
36
37
  # @option options [String] image_src the file location of the image you will render
37
38
  # @option options [String] name the name attribute for the rendered image
38
- # @option options [String] descr the description of the image rendered
39
+ # @option options [String] descr the description of the image rendered
39
40
  def initialize(drawing, options={})
40
41
  @drawing = drawing
41
42
  @width = 0
42
43
  @height = 0
43
- drawing.anchors << self
44
+ drawing.anchors << self
44
45
  @from = Marker.new
45
46
  options.each do |o|
46
47
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
@@ -60,23 +61,24 @@ module Axlsx
60
61
  @drawing.anchors.index(self)
61
62
  end
62
63
 
63
- # Serializes the anchor
64
- # @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
65
67
  # @return [String]
66
- def to_xml(xml)
67
- xml[:xdr].oneCellAnchor {
68
- xml.from {
69
- from.to_xml(xml)
70
- }
71
- xml.ext ext
72
- @object.to_xml(xml)
73
- xml.clientData
74
- }
75
- 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
76
78
 
77
79
  private
78
80
 
79
- # 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
80
82
  # !{:cx=>[Integer], :cy=>[Integer]
81
83
  # @return [Hash]
82
84
  def ext