axlsx 1.0.15 → 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 (176) hide show
  1. data/.yardopts +1 -0
  2. data/CHANGELOG.md +40 -2
  3. data/README.md +223 -92
  4. data/examples/example.csv +1000 -0
  5. data/examples/example.rb +266 -132
  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 +27 -12
  22. data/lib/axlsx/drawing/graphic_frame.rb +22 -21
  23. data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
  24. data/lib/axlsx/drawing/hyperlink.rb +96 -0
  25. data/lib/axlsx/drawing/hyperlink.rb~ +64 -0
  26. data/lib/axlsx/drawing/line_3D_chart.rb +31 -28
  27. data/lib/axlsx/drawing/line_series.rb +12 -11
  28. data/lib/axlsx/drawing/marker.rb +11 -8
  29. data/lib/axlsx/drawing/named_axis_data.rb +36 -0
  30. data/lib/axlsx/drawing/one_cell_anchor.rb +18 -16
  31. data/lib/axlsx/drawing/pic.rb +47 -33
  32. data/lib/axlsx/drawing/picture_locking.rb +22 -18
  33. data/lib/axlsx/drawing/pie_3D_chart.rb +11 -8
  34. data/lib/axlsx/drawing/pie_series.rb +16 -12
  35. data/lib/axlsx/drawing/scaling.rb +11 -10
  36. data/lib/axlsx/drawing/scatter_chart.rb +69 -0
  37. data/lib/axlsx/drawing/scatter_series.rb +39 -0
  38. data/lib/axlsx/drawing/ser_axis.rb +11 -10
  39. data/lib/axlsx/drawing/series.rb +16 -15
  40. data/lib/axlsx/drawing/series_title.rb +15 -14
  41. data/lib/axlsx/drawing/title.rb +27 -26
  42. data/lib/axlsx/drawing/two_cell_anchor.rb +19 -20
  43. data/lib/axlsx/drawing/val_axis.rb +9 -7
  44. data/lib/axlsx/drawing/val_axis_data.rb +18 -17
  45. data/lib/axlsx/drawing/view_3D.rb +23 -20
  46. data/lib/axlsx/package.rb +117 -52
  47. data/lib/axlsx/rels/relationship.rb +27 -8
  48. data/lib/axlsx/rels/relationships.rb +9 -2
  49. data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
  50. data/lib/axlsx/stylesheet/border.rb +28 -23
  51. data/lib/axlsx/stylesheet/border_pr.rb +17 -15
  52. data/lib/axlsx/stylesheet/cell_alignment.rb +24 -21
  53. data/lib/axlsx/stylesheet/cell_protection.rb +11 -7
  54. data/lib/axlsx/stylesheet/cell_style.rb +9 -5
  55. data/lib/axlsx/stylesheet/color.rb +21 -14
  56. data/lib/axlsx/stylesheet/fill.rb +8 -5
  57. data/lib/axlsx/stylesheet/font.rb +22 -14
  58. data/lib/axlsx/stylesheet/gradient_fill.rb +20 -17
  59. data/lib/axlsx/stylesheet/gradient_stop.rb +10 -6
  60. data/lib/axlsx/stylesheet/num_fmt.rb +13 -6
  61. data/lib/axlsx/stylesheet/pattern_fill.rb +26 -10
  62. data/lib/axlsx/stylesheet/styles.rb +53 -41
  63. data/lib/axlsx/stylesheet/table_style.rb +10 -4
  64. data/lib/axlsx/stylesheet/table_style_element.rb +11 -7
  65. data/lib/axlsx/stylesheet/table_styles.rb +12 -8
  66. data/lib/axlsx/stylesheet/xf.rb +30 -25
  67. data/lib/axlsx/util/cbf.rb +69 -33
  68. data/lib/axlsx/util/constants.rb +39 -20
  69. data/lib/axlsx/util/ms_off_crypto.rb +10 -10
  70. data/lib/axlsx/util/parser.rb +1 -0
  71. data/lib/axlsx/util/simple_typed_list.rb +20 -10
  72. data/lib/axlsx/util/storage.rb +1 -1
  73. data/lib/axlsx/util/validators.rb +23 -7
  74. data/lib/axlsx/version.rb +5 -2
  75. data/lib/axlsx/workbook/shared_strings_table.rb +69 -0
  76. data/lib/axlsx/workbook/shared_strings_table.rb~ +69 -0
  77. data/lib/axlsx/workbook/workbook.rb +82 -26
  78. data/lib/axlsx/workbook/worksheet/cell.rb +172 -117
  79. data/lib/axlsx/workbook/worksheet/col.rb +114 -0
  80. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  81. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
  82. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
  83. data/lib/axlsx/workbook/worksheet/row.rb +53 -21
  84. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  85. data/lib/axlsx/workbook/worksheet/table.rb +96 -0
  86. data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
  87. data/lib/axlsx/workbook/worksheet/worksheet.rb +270 -121
  88. data/lib/axlsx.rb +41 -14
  89. data/lib/schema/dc.xsd +5 -5
  90. data/lib/schema/dcmitype.xsd +5 -3
  91. data/lib/schema/dcterms.xsd +15 -15
  92. data/lib/schema/opc-coreProperties.xsd +6 -2
  93. data/lib/schema/xml.xsd +7 -8
  94. data/test/#benchmark.txt# +7 -0
  95. data/test/#tc_helper.rb# +3 -0
  96. data/test/benchmark.rb +81 -0
  97. data/test/benchmark.rb~ +0 -0
  98. data/test/benchmark.txt +6 -0
  99. data/test/benchmark.txt~ +6 -0
  100. data/test/content_type/tc_content_type.rb +31 -31
  101. data/test/content_type/tc_default.rb +9 -22
  102. data/test/content_type/tc_override.rb +8 -21
  103. data/test/doc_props/tc_app.rb +2 -8
  104. data/test/doc_props/tc_core.rb +6 -7
  105. data/test/drawing/tc_axis.rb +7 -3
  106. data/test/drawing/tc_bar_3D_chart.rb +6 -7
  107. data/test/drawing/tc_bar_series.rb +4 -5
  108. data/test/drawing/tc_cat_axis.rb +2 -3
  109. data/test/drawing/tc_cat_axis_data.rb +2 -3
  110. data/test/drawing/tc_chart.rb +13 -14
  111. data/test/drawing/tc_drawing.rb +7 -8
  112. data/test/drawing/tc_graphic_frame.rb +3 -4
  113. data/test/drawing/tc_hyperlink.rb +69 -0
  114. data/test/drawing/tc_line_3d_chart.rb +5 -6
  115. data/test/drawing/tc_line_series.rb +3 -4
  116. data/test/drawing/tc_marker.rb +3 -4
  117. data/test/drawing/tc_one_cell_anchor.rb +6 -7
  118. data/test/drawing/tc_pic.rb +13 -8
  119. data/test/drawing/tc_picture_locking.rb +2 -3
  120. data/test/drawing/tc_pie_3D_chart.rb +5 -6
  121. data/test/drawing/tc_pie_series.rb +4 -5
  122. data/test/drawing/tc_scaling.rb +3 -4
  123. data/test/drawing/tc_scatter_chart.rb +43 -0
  124. data/test/drawing/tc_scatter_series.rb +20 -0
  125. data/test/drawing/tc_ser_axis.rb +2 -3
  126. data/test/drawing/tc_series.rb +4 -5
  127. data/test/drawing/tc_series_title.rb +4 -5
  128. data/test/drawing/tc_title.rb +4 -5
  129. data/test/drawing/tc_two_cell_anchor.rb +4 -5
  130. data/test/drawing/tc_val_axis.rb +2 -3
  131. data/test/drawing/tc_val_axis_data.rb +2 -3
  132. data/test/drawing/tc_view_3D.rb +6 -7
  133. data/test/example.csv +1000 -0
  134. data/test/example.xlsx +0 -0
  135. data/test/example_streamed.xlsx +0 -0
  136. data/test/profile.rb +33 -0
  137. data/test/rels/tc_relationship.rb +10 -6
  138. data/test/rels/tc_relationships.rb +4 -5
  139. data/test/stylesheet/tc_border.rb +3 -4
  140. data/test/stylesheet/tc_border_pr.rb +3 -4
  141. data/test/stylesheet/tc_cell_alignment.rb +10 -6
  142. data/test/stylesheet/tc_cell_protection.rb +2 -3
  143. data/test/stylesheet/tc_cell_style.rb +2 -3
  144. data/test/stylesheet/tc_color.rb +2 -3
  145. data/test/stylesheet/tc_fill.rb +1 -2
  146. data/test/stylesheet/tc_font.rb +12 -5
  147. data/test/stylesheet/tc_gradient_fill.rb +1 -2
  148. data/test/stylesheet/tc_gradient_stop.rb +1 -2
  149. data/test/stylesheet/tc_num_fmt.rb +1 -2
  150. data/test/stylesheet/tc_pattern_fill.rb +3 -4
  151. data/test/stylesheet/tc_styles.rb +16 -6
  152. data/test/stylesheet/tc_table_style.rb +2 -3
  153. data/test/stylesheet/tc_table_style_element.rb +2 -3
  154. data/test/stylesheet/tc_table_styles.rb +3 -4
  155. data/test/stylesheet/tc_xf.rb +16 -17
  156. data/test/tc_axlsx.rb +39 -0
  157. data/test/tc_axlsx.rb~ +0 -0
  158. data/test/tc_helper.rb +3 -0
  159. data/test/tc_helper.rb~ +3 -0
  160. data/test/tc_package.rb +43 -9
  161. data/test/util/tc_simple_typed_list.rb +8 -9
  162. data/test/util/tc_validators.rb +7 -8
  163. data/test/workbook/tc_shared_strings_table.rb +38 -0
  164. data/test/workbook/tc_workbook.rb +32 -6
  165. data/test/workbook/worksheet/table/tc_table.rb +71 -0
  166. data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
  167. data/test/workbook/worksheet/tc_cell.rb +70 -13
  168. data/test/workbook/worksheet/tc_col.rb +59 -0
  169. data/test/workbook/worksheet/tc_col.rb~ +10 -0
  170. data/test/workbook/worksheet/tc_date_time_converter.rb +126 -0
  171. data/test/workbook/worksheet/tc_page_margins.rb +97 -0
  172. data/test/workbook/worksheet/tc_row.rb +54 -4
  173. data/test/workbook/worksheet/tc_worksheet.rb +198 -31
  174. metadata +167 -111
  175. data/test/drawing/tc_line_series.tc~ +0 -34
  176. data/test/drawing/tc_picture_locking.rb~ +0 -77
@@ -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
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,9 +29,11 @@ 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'
36
+ require 'axlsx/drawing/hyperlink.rb'
32
37
 
33
38
  # A Drawing is a canvas for charts. Each worksheet has a single drawing that manages anchors.
34
39
  # The anchors reference the charts via graphical frames. This is not a trivial relationship so please do follow the advice in the note.
@@ -41,7 +46,7 @@ module Axlsx
41
46
  # The worksheet that owns the drawing
42
47
  # @return [Worksheet]
43
48
  attr_reader :worksheet
44
-
49
+
45
50
  # A collection of anchors for this drawing
46
51
  # only TwoCellAnchors are supported in this version
47
52
  # @return [SimpleTypedList]
@@ -79,6 +84,13 @@ module Axlsx
79
84
  charts.map { |a| a.object.chart }
80
85
  end
81
86
 
87
+ # An array of hyperlink objects associated with this drawings images
88
+ # @return [Array]
89
+ def hyperlinks
90
+ links = self.images.select { |a| a.hyperlink.is_a?(Hyperlink) }
91
+ links.map { |a| a.hyperlink }
92
+ end
93
+
82
94
  # An array of image objects that are associated with this drawing's anchors
83
95
  # @return [Array]
84
96
  def images
@@ -120,18 +132,21 @@ module Axlsx
120
132
  images.each do |image|
121
133
  r << Relationship.new(IMAGE_R, "../#{image.pn}")
122
134
  end
135
+ hyperlinks.each do |hyperlink|
136
+ r << Relationship.new(HYPERLINK_R, hyperlink.href, :target_mode => :External)
137
+ end
123
138
  r
124
139
  end
125
140
 
126
- # Serializes the drawing
141
+ # Serializes the object
142
+ # @param [String] str
127
143
  # @return [String]
128
- def to_xml
129
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
130
- xml.send('xdr:wsDr', :'xmlns:xdr'=>XML_NS_XDR, :'xmlns:a'=>XML_NS_A, :'xmlns:c'=>XML_NS_C) {
131
- anchors.each {|anchor| anchor.to_xml(xml) }
132
- }
133
- end
134
- builder.to_xml
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>'
135
149
  end
150
+
136
151
  end
137
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
File without changes
@@ -0,0 +1,96 @@
1
+ # encoding: UTF-8
2
+ module Axlsx
3
+ # a hyperlink object adds an action to an image when clicked so that when the image is clicked the link is fecthed.
4
+ # @note using the hyperlink option when calling add_image on a drawing object is the recommended way to manage hyperlinks
5
+ # @see {file:README} README
6
+ class Hyperlink
7
+
8
+ # The destination of the hyperlink stored in the drawing's relationships document.
9
+ # @return [String]
10
+ attr_accessor :href
11
+
12
+ # The spec says: Specifies the URL when it has been determined by the generating application that the URL is invalid. That is the generating application can still store the URL but it is known that this URL is not correct.
13
+ #
14
+ # What exactly that means is beyond me so if you ever use this, let me know!
15
+ # @return [String]
16
+ attr_accessor :invalidUrl
17
+
18
+ #An action to take when the link is clicked. The specification says "This can be used to specify a slide to be navigated to or a script of code to be run." but in most cases you will not need to do anything with this. MS does reserve a few interesting strings. @see http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
19
+ # @return [String]
20
+ attr_accessor :action
21
+
22
+ # Specifies if all sound events should be terminated when this link is clicked.
23
+ # @return [Boolean]
24
+ attr_reader :endSnd
25
+
26
+ # @see endSnd
27
+ # @param [Boolean] v The boolean value indicating the termination of playing sounds on click
28
+ # @return [Boolean]
29
+ def endSnd=(v) Axlsx::validate_boolean(v); @endSnd = v end
30
+
31
+ # indicates that the link has already been clicked.
32
+ # @return [Boolean]
33
+ attr_reader :highlightClick
34
+
35
+ # @see highlightClick
36
+ # @param [Boolean] v The value to assign
37
+ def highlightClick=(v) Axlsx::validate_boolean(v); @highlightClick = v end
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.
40
+ # @return [Boolean]
41
+ attr_reader :history
42
+
43
+ # @see history
44
+ # param [Boolean] v The value to assing
45
+ def history=(v) Axlsx::validate_boolean(v); @history = v end
46
+
47
+ # From the specs: Specifies the target frame that is to be used when opening this hyperlink. When the hyperlink is activated this attribute is used to determine if a new window is launched for viewing or if an existing one can be used. If this attribute is omitted, than a new window is opened.
48
+ # @return [String]
49
+ attr_accessor :tgtFrame
50
+
51
+ # Text to show when you mouse over the hyperlink. If you do not set this, the href property will be shown.
52
+ # @return [String]
53
+ attr_accessor :tooltip
54
+
55
+ #Creates a hyperlink object
56
+ # parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent
57
+ # @param [Pic] parent
58
+ # @option options [String] tooltip message shown when hyperlinked object is hovered over with mouse.
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.
61
+ # @option options [String] href the target resource this hyperlink links to.
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
+ # @option options [Boolean] endSnd terminate any sound events when processing this link
64
+ # @option options [Boolean] history include this link in the list of visited links for the applications history.
65
+ # @option options [Boolean] highlightClick indicate that the link has already been visited.
66
+ def initialize(parent, options={})
67
+ DataTypeValidator.validate "Hyperlink.parent", [Pic], parent
68
+ @parent = parent
69
+ options.each do |o|
70
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
71
+ end
72
+ yield self if block_given?
73
+
74
+ end
75
+
76
+ # Serializes the object
77
+ # @param [String] str
78
+ # @return [String]
79
+ def to_xml_string(str = '')
80
+ h = self.instance_values.merge({:'r:id' => "rId#{id}", :'xmlns:r' => XML_NS_R })
81
+ h.delete('href')
82
+ h.delete('parent')
83
+ str << '<a:hlinkClick '
84
+ str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
85
+ str << '/>'
86
+ end
87
+
88
+ private
89
+ # The relational ID for this hyperlink
90
+ # @return [Integer]
91
+ def id
92
+ @parent.anchor.drawing.charts.size + @parent.anchor.drawing.images.size + @parent.anchor.drawing.hyperlinks.index(self) + 1
93
+ end
94
+
95
+ end
96
+ end
@@ -0,0 +1,64 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Axlsx
3
+ # a hlinkClick object adds a click behaviour to a drawing object.
4
+ # using the hlink_click method on a drawing object is the recommended way to manage hlinks
5
+ # @see Pic#link_to
6
+ class Hyperlink
7
+
8
+ # the type of hyper link defines the onclick or mouseover trigger.
9
+ # type must be one of :hlinkClick or :hlinkMouse
10
+ def type
11
+ @type ||= :hlinkClick
12
+ end
13
+
14
+ # sets the type of the object.
15
+ # @param [Symbol] type one of :hlinkClick or hlinkMouse
16
+ def type(v) RestrictionValidator.validate "Hyperlink.type", [:hlinkClick, :hlinkMouse], v; @type = v end
17
+
18
+ # The destination of the hyperlink
19
+ # This value is actually stored in the drawings .rels. doc as a relationship.
20
+ attr_accessor :href
21
+
22
+ # The docs say:
23
+ # Specifies the URL when it has been determined by the generating application that the URL is invalid. That is the generating application can still store the URL but it is known that this URL is not correct.
24
+ attr_accessor :invalidUrl
25
+
26
+ # Specifies the target frame that is to be used when opening this hyperlink. When the hyperlink is activated this attribute is used to determine if a new window is launched for viewing or if an existing one can be used. If this attribute is omitted, than a new window is opened.
27
+ attr_accessor :tgtFrame
28
+
29
+ # Specifies the tooltip that should be displayed when the hyperlink text is hovered over with the mouse. If this attribute is omitted, than the hyperlink text itself can be displayed.
30
+ attr_accessor :tooltip
31
+
32
+ #Creates a hyperlink object
33
+ # parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent
34
+ # @param [Pic] parent
35
+ # @option [String] tooltip message shown when hyperlinked object is hovered over with mouse.
36
+ # @option [String] tgtFrame Target frame for opening hyperlink
37
+ # @option [String] invalidUrl supposedly use to store the href when we know it is an invalid resource.
38
+ # @option [String] href the target resource this hyperlink links to.
39
+ def initialize(parent, options=>{})
40
+ DataTypeValidator.validate "Hyperlink.parent", [Pic], parent
41
+ @parent = parent
42
+ options.each do |o|
43
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
44
+ end
45
+ end
46
+
47
+ # The index of this hyperlink in the owning document's hyperlinks collection
48
+ # @returns [Integer]
49
+ def index
50
+ self.parent.anchor.drawing.hyperlinks.index(self)
51
+ end
52
+
53
+ # The relational ID for this hyperlink
54
+ # @returns [String]
55
+ def r:id
56
+ reference_count = self.parent.anchor.drawing.charts.size + self.parent.anchor.drawing.images.size + index
57
+
58
+ end
59
+
60
+ def to_xml(xml)
61
+ xml.send(type,
62
+ end
63
+ end
64
+ end
@@ -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