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
@@ -17,7 +17,7 @@ module Axlsx
17
17
  attr_reader :Manager
18
18
 
19
19
  # @return [String] The name of the company generating the document.
20
- attr_reader :Company
20
+ attr_reader :Company
21
21
 
22
22
  # @return [Integer] The number of pages in the document.
23
23
  attr_reader :Pages
@@ -43,7 +43,7 @@ module Axlsx
43
43
  # @return [Integer] The number of slides that have notes.
44
44
  attr_reader :Notes
45
45
 
46
- # @return [Integer] The total amount of time spent editing.
46
+ # @return [Integer] The total amount of time spent editing.
47
47
  attr_reader :TotalTime
48
48
 
49
49
  # @return [Integer] The number of hidden slides.
@@ -60,11 +60,11 @@ module Axlsx
60
60
 
61
61
  # @return [Integer] The number of characters in the document including spaces.
62
62
  attr_reader :CharactersWithSpaces
63
-
63
+
64
64
  # @return [Boolean] Indicates if the document is shared.
65
65
  attr_reader :ShareDoc
66
66
 
67
- # @return [String] The base for hyper links in the document.
67
+ # @return [String] The base for hyper links in the document.
68
68
  attr_reader :HyperLinkBase
69
69
 
70
70
  # @return [Boolean] Indicates that the hyper links in the document have been changed.
@@ -96,7 +96,7 @@ module Axlsx
96
96
  # @option options [Boolean] ScaleCrop
97
97
  # @option options [Boolean] LinksUpToDate
98
98
  # @option options [Integer] CharactersWithSpaces
99
- # @option options [Boolean] ShareDoc
99
+ # @option options [Boolean] ShareDoc
100
100
  # @option options [String] HyperLinkBase
101
101
  # @option options [String] HyperlinksChanged
102
102
  # @option options [String] Application
@@ -109,70 +109,67 @@ module Axlsx
109
109
  end
110
110
 
111
111
  # Sets the Template property of your app.xml file
112
- def Template=(v) Axlsx::validate_string v; @Template = v; end
112
+ def Template=(v) Axlsx::validate_string v; @Template = v; end
113
113
 
114
114
  # Sets the Manager property of your app.xml file
115
- def Manager=(v) Axlsx::validate_string v; @Manager = v; end
115
+ def Manager=(v) Axlsx::validate_string v; @Manager = v; end
116
116
 
117
117
  # Sets the Company property of your app.xml file
118
- def Company=(v) Axlsx::validate_string v; @Company = v; end
118
+ def Company=(v) Axlsx::validate_string v; @Company = v; end
119
119
 
120
120
  # Sets the Pages property of your app.xml file
121
- def Pages=(v) Axlsx::validate_int v; @Pages = v; end
121
+ def Pages=(v) Axlsx::validate_int v; @Pages = v; end
122
122
 
123
123
  # Sets the Words property of your app.xml file
124
- def Words=(v) Axlsx::validate_int v; @Words = v; end
124
+ def Words=(v) Axlsx::validate_int v; @Words = v; end
125
125
 
126
126
  # Sets the Characters property of your app.xml file
127
- def Characters=(v) Axlsx::validate_int v; @Characters = v; end
127
+ def Characters=(v) Axlsx::validate_int v; @Characters = v; end
128
128
 
129
129
 
130
130
  # Sets the PresentationFormat property of your app.xml file
131
- def PresentationFormat=(v) Axlsx::validate_string v; @PresentationFormat = v; end
131
+ def PresentationFormat=(v) Axlsx::validate_string v; @PresentationFormat = v; end
132
132
  # Sets the Lines property of your app.xml file
133
- def Lines=(v) Axlsx::validate_int v; @Lines = v; end
133
+ def Lines=(v) Axlsx::validate_int v; @Lines = v; end
134
134
  # Sets the Paragraphs property of your app.xml file
135
- def Paragraphs=(v) Axlsx::validate_int v; @Paragraphs = v; end
135
+ def Paragraphs=(v) Axlsx::validate_int v; @Paragraphs = v; end
136
136
  # Sets the Slides property of your app.xml file
137
- def Slides=(v) Axlsx::validate_int v; @Slides = v; end
137
+ def Slides=(v) Axlsx::validate_int v; @Slides = v; end
138
138
  # Sets the Notes property of your app.xml file
139
- def Notes=(v) Axlsx::validate_int v; @Notes = v; end
139
+ def Notes=(v) Axlsx::validate_int v; @Notes = v; end
140
140
  # Sets the TotalTime property of your app.xml file
141
- def TotalTime=(v) Axlsx::validate_int v; @TotalTime = v; end
141
+ def TotalTime=(v) Axlsx::validate_int v; @TotalTime = v; end
142
142
  # Sets the HiddenSlides property of your app.xml file
143
- def HiddenSlides=(v) Axlsx::validate_int v; @HiddenSlides = v; end
143
+ def HiddenSlides=(v) Axlsx::validate_int v; @HiddenSlides = v; end
144
144
  # Sets the MMClips property of your app.xml file
145
- def MMClips=(v) Axlsx::validate_int v; @MMClips = v; end
145
+ def MMClips=(v) Axlsx::validate_int v; @MMClips = v; end
146
146
  # Sets the ScaleCrop property of your app.xml file
147
- def ScaleCrop=(v) Axlsx::validate_boolean v; @ScaleCrop = v; end
147
+ def ScaleCrop=(v) Axlsx::validate_boolean v; @ScaleCrop = v; end
148
148
  # Sets the LinksUpToDate property of your app.xml file
149
- def LinksUpToDate=(v) Axlsx::validate_boolean v; @LinksUpToDate = v; end
149
+ def LinksUpToDate=(v) Axlsx::validate_boolean v; @LinksUpToDate = v; end
150
150
  # Sets the CharactersWithSpaces property of your app.xml file
151
- def CharactersWithSpaces=(v) Axlsx::validate_int v; @CharactersWithSpaces = v; end
151
+ def CharactersWithSpaces=(v) Axlsx::validate_int v; @CharactersWithSpaces = v; end
152
152
  # Sets the ShareDoc property of your app.xml file
153
- def ShareDoc=(v) Axlsx::validate_boolean v; @ShareDoc = v; end
153
+ def ShareDoc=(v) Axlsx::validate_boolean v; @ShareDoc = v; end
154
154
  # Sets the HyperLinkBase property of your app.xml file
155
- def HyperLinkBase=(v) Axlsx::validate_string v; @HyperLinkBase = v; end
155
+ def HyperLinkBase=(v) Axlsx::validate_string v; @HyperLinkBase = v; end
156
156
  # Sets the HyperLinksChanged property of your app.xml file
157
- def HyperlinksChanged=(v) Axlsx::validate_boolean v; @HyperlinksChanged = v; end
157
+ def HyperlinksChanged=(v) Axlsx::validate_boolean v; @HyperlinksChanged = v; end
158
158
  # Sets the Application property of your app.xml file
159
- def Application=(v) Axlsx::validate_string v; @Application = v; end
159
+ def Application=(v) Axlsx::validate_string v; @Application = v; end
160
160
  # Sets the AppVersion property of your app.xml file
161
- def AppVersion=(v) Axlsx::validate_string v; @AppVersion = v; end
161
+ def AppVersion=(v) Axlsx::validate_string v; @AppVersion = v; end
162
162
  # Sets the DocSecurity property of your app.xml file
163
- def DocSecurity=(v) Axlsx::validate_int v; @DocSecurity = v; end
164
-
165
- # Generate an app.xml document
166
- # @return [String] The document as a string
167
- def to_xml()
168
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
169
- xml.send(:Properties, :xmlns => APP_NS, :'xmlns:vt' => APP_NS_VT) {
170
- self.instance_values.each do |name, value|
171
- xml.send(name, value)
172
- end
173
- }
174
- end
175
- builder.to_xml(:save_with => 0)
163
+ def DocSecurity=(v) Axlsx::validate_int v; @DocSecurity = v; end
164
+
165
+ # Serialize the app.xml document
166
+ # @return [String]
167
+ def to_xml_string(str = '')
168
+ str << '<?xml version="1.0" encoding="UTF-8"?>'
169
+ str << '<Properties xmlns="' << APP_NS << '" xmlns:vt="' << APP_NS_VT << '">'
170
+ str << instance_values.map { |key, value| '<' << key.to_s << '>' << value.to_s << '</' << key.to_s << '>' }.join
171
+ str << '</Properties>'
176
172
  end
173
+
177
174
  end
178
175
  end
@@ -7,29 +7,24 @@ module Axlsx
7
7
  # The author of the document. By default this is 'axlsx'
8
8
  # @return [String]
9
9
  attr_accessor :creator
10
-
10
+
11
11
  # Creates a new Core object.
12
12
  # @option options [String] creator
13
13
  def initialize(options={})
14
- @creator = options[:creator] || 'axlsx'
14
+ @creator = options[:creator] || 'axlsx'
15
15
  end
16
16
 
17
- # Serializes the core object. The created dcterms item is set to the current time when this method is called.
17
+ # serializes the core.xml document
18
18
  # @return [String]
19
- def to_xml()
20
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
21
- xml.send('cp:coreProperties',
22
- :"xmlns:cp" => CORE_NS,
23
- :'xmlns:dc' => CORE_NS_DC,
24
- :'xmlns:dcmitype'=>CORE_NS_DCMIT,
25
- :'xmlns:dcterms'=>CORE_NS_DCT,
26
- :'xmlns:xsi'=>CORE_NS_XSI) {
27
- xml['dc'].creator self.creator
28
- xml['dcterms'].created Time.now.strftime('%Y-%m-%dT%H:%M:%S'), :'xsi:type'=>"dcterms:W3CDTF"
29
- xml['cp'].revision 0
30
- }
31
- end
32
- builder.to_xml(:save_with => 0)
19
+ def to_xml_string(str = '')
20
+ str << '<?xml version="1.0" encoding="UTF-8"?>'
21
+ str << '<cp:coreProperties xmlns:cp="' << CORE_NS << '" xmlns:dc="' << CORE_NS_DC << '" '
22
+ str << 'xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" '
23
+ str << 'xmlns:xsi="' << CORE_NS_XSI << '">'
24
+ str << '<dc:creator>' << self.creator << '</dc:creator>'
25
+ str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << Time.now.strftime('%Y-%m-%dT%H:%M:%S') << '</dcterms:created>'
26
+ str << '<cp:revision>0</cp:revision>'
27
+ str << '</cp:coreProperties>'
33
28
  end
34
29
  end
35
30
  end
@@ -3,7 +3,7 @@ module Axlsx
3
3
  # the access class defines common properties and values for a chart axis.
4
4
  class Axis
5
5
 
6
- # the id of the axis.
6
+ # the id of the axis.
7
7
  # @return [Integer]
8
8
  attr_reader :axId
9
9
 
@@ -15,7 +15,7 @@ module Axlsx
15
15
  # @see Scaling
16
16
  # @return [Scaling]
17
17
  attr_reader :scaling
18
-
18
+
19
19
  # The position of the axis
20
20
  # must be one of [:l, :r, :t, :b]
21
21
  # @return [Symbol]
@@ -34,7 +34,11 @@ module Axlsx
34
34
  # specifies how the perpendicular axis is crossed
35
35
  # must be one of [:autoZero, :min, :max]
36
36
  # @return [Symbol]
37
- attr_reader :crosses
37
+ attr_reader :crosses
38
+
39
+ # specifies if gridlines should be shown in the chart
40
+ # @return [Boolean]
41
+ attr_reader :gridlines
38
42
 
39
43
  # Creates an Axis object
40
44
  # @param [Integer] axId the id of this axis
@@ -49,11 +53,12 @@ module Axlsx
49
53
  @axId = axId
50
54
  @crossAx = crossAx
51
55
  @format_code = "General"
52
- @scaling = Scaling.new(:orientation=>:minMax)
56
+ @scaling = Scaling.new(:orientation=>:minMax)
53
57
  self.axPos = :b
54
58
  self.tickLblPos = :nextTo
55
59
  self.format_code = "General"
56
60
  self.crosses = :autoZero
61
+ self.gridlines = true
57
62
  options.each do |o|
58
63
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
59
64
  end
@@ -70,25 +75,39 @@ module Axlsx
70
75
  # default :General
71
76
  def format_code=(v) Axlsx::validate_string(v); @format_code = v; end
72
77
 
78
+ # Specify if gridlines should be shown for this axis
79
+ # default true
80
+ def gridlines=(v) Axlsx::validate_boolean(v); @gridlines = v; end
81
+
73
82
  # specifies how the perpendicular axis is crossed
74
83
  # must be one of [:autoZero, :min, :max]
75
84
  def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end
76
85
 
77
- # Serializes the common axis
78
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
86
+
87
+ # Serializes the object
88
+ # @param [String] str
79
89
  # @return [String]
80
- def to_xml(xml)
81
- xml.axId :val=>@axId
82
- @scaling.to_xml(xml)
83
- xml.delete :val=>0
84
- xml.axPos :val=>@axPos
85
- xml.majorGridlines
86
- xml.numFmt :formatCode => @format_code, :sourceLinked=>"1"
87
- xml.majorTickMark :val=>"none"
88
- xml.minorTickMark :val=>"none"
89
- xml.tickLblPos :val=>@tickLblPos
90
- xml.crossAx :val=>@crossAx
91
- xml.crosses :val=>@crosses
92
- end
90
+ def to_xml_string(str = '')
91
+ str << '<c:axId val="' << @axId.to_s << '"/>'
92
+ @scaling.to_xml_string str
93
+ str << '<c:delete val="0"/>'
94
+ str << '<c:axPos val="' << @axPos.to_s << '"/>'
95
+ str << '<c:majorGridlines>'
96
+ if self.gridlines == false
97
+ str << '<c:spPr>'
98
+ str << '<a:ln>'
99
+ str << '<a:noFill/>'
100
+ str << '</a:ln>'
101
+ str << '</c:spPr>'
102
+ end
103
+ str << '</c:majorGridlines>'
104
+ str << '<c:numFmt formatCode="' << @format_code << '" sourceLinked="1"/>'
105
+ str << '<c:majorTickMark val="none"/>'
106
+ str << '<c:minorTickMark val="none"/>'
107
+ str << '<c:tickLblPos val="' << @tickLblPos.to_s << '"/>'
108
+ str << '<c:crossAx val="' << @crossAx.to_s << '"/>'
109
+ str << '<c:crosses val="' << @crosses.to_s << '"/>'
110
+ end
111
+
93
112
  end
94
113
  end
@@ -41,7 +41,7 @@ module Axlsx
41
41
 
42
42
  # validation regex for gap amount percent
43
43
  GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
44
-
44
+
45
45
  # Creates a new bar chart object
46
46
  # @param [GraphicFrame] frame The workbook that owns this chart.
47
47
  # @option options [Cell, String] title
@@ -67,14 +67,14 @@ module Axlsx
67
67
  @valAxId = rand(8 ** 8)
68
68
  @catAxis = CatAxis.new(@catAxId, @valAxId)
69
69
  @valAxis = ValAxis.new(@valAxId, @catAxId, :tickLblPos => :low)
70
- super(frame, options)
70
+ super(frame, options)
71
71
  @series_type = BarSeries
72
72
  @view3D = View3D.new({:rAngAx=>1}.merge(options))
73
73
  end
74
74
 
75
75
  # The direction of the bars in the chart
76
76
  # must be one of [:bar, :col]
77
- def barDir=(v)
77
+ def barDir=(v)
78
78
  RestrictionValidator.validate "Bar3DChart.barDir", [:bar, :col], v
79
79
  @barDir = v
80
80
  end
@@ -100,38 +100,39 @@ module Axlsx
100
100
 
101
101
  # The shabe of the bars or columns
102
102
  # must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax]
103
- def shape=(v)
103
+ def shape=(v)
104
104
  RestrictionValidator.validate "Bar3DChart.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v
105
105
  @shape = v
106
106
  end
107
-
108
- # Serializes the bar chart
107
+
108
+ # Serializes the object
109
+ # @param [String] str
109
110
  # @return [String]
110
- def to_xml
111
- super() do |xml|
112
- xml.bar3DChart {
113
- xml.barDir :val => barDir
114
- xml.grouping :val=>grouping
115
- xml.varyColors :val=>1
116
- @series.each { |ser| ser.to_xml(xml) }
117
- xml.dLbls {
118
- xml.showLegendKey :val=>0
119
- xml.showVal :val=>0
120
- xml.showCatName :val=>0
121
- xml.showSerName :val=>0
122
- xml.showPercent :val=>0
123
- xml.showBubbleSize :val=>0
124
- }
125
- xml.gapWidth :val=>@gapWidth unless @gapWidth.nil?
126
- xml.gapDepth :val=>@gapDepth unless @gapDepth.nil?
127
- xml.shape :val=>@shape unless @shape.nil?
128
- xml.axId :val=>@catAxId
129
- xml.axId :val=>@valAxId
130
- xml.axId :val=>0
131
- }
132
- @catAxis.to_xml(xml)
133
- @valAxis.to_xml(xml)
111
+ def to_xml_string(str = '')
112
+ super(str) do |str_inner|
113
+ str_inner << '<c:bar3DChart>'
114
+ str_inner << '<c:barDir val="' << barDir.to_s << '"/>'
115
+ str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
116
+ str_inner << '<c:varyColors val="1"/>'
117
+ @series.each { |ser| ser.to_xml_string(str_inner) }
118
+ str_inner << '<c:dLbls>'
119
+ str_inner << '<c:showLegendKey val="0"/>'
120
+ str_inner << '<c:showVal val="0"/>'
121
+ str_inner << '<c:showCatName val="0"/>'
122
+ str_inner << '<c:showSerName val="0"/>'
123
+ str_inner << '<c:showPercent val="0"/>'
124
+ str_inner << '<c:showBubbleSize val="0"/>'
125
+ str_inner << '</c:dLbls>'
126
+ str_inner << '<c:gapWidth val="' << @gapWidth.to_s << '"/>' unless @gapWidth.nil?
127
+ str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
128
+ str_inner << '<c:shape val="' << @shape.to_s << '"/>' unless @shape.nil?
129
+ str_inner << '<c:axId val="' << @catAxId.to_s << '"/>'
130
+ str_inner << '<c:axId val="' << @valAxId.to_s << '"/>'
131
+ str_inner << '<c:axId val="0"/>'
132
+ str_inner << '</c:bar3DChart>'
133
+ @catAxis.to_xml_string str_inner
134
+ @valAxis.to_xml_string str_inner
134
135
  end
135
- end
136
- end
136
+ end
137
+ end
137
138
  end
@@ -6,8 +6,8 @@ module Axlsx
6
6
  # @see Chart#add_series
7
7
  class BarSeries < Series
8
8
 
9
-
10
- # The data for this series.
9
+
10
+ # The data for this series.
11
11
  # @return [Array, SimpleTypedList]
12
12
  attr_reader :data
13
13
 
@@ -31,28 +31,27 @@ module Axlsx
31
31
  super(chart, options)
32
32
  self.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
33
33
  self.data = ValAxisData.new(options[:data]) unless options[:data].nil?
34
- end
34
+ end
35
35
 
36
36
  # The shabe of the bars or columns
37
37
  # must be one of [:percentStacked, :clustered, :standard, :stacked]
38
- def shape=(v)
38
+ def shape=(v)
39
39
  RestrictionValidator.validate "BarSeries.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v
40
40
  @shape = v
41
41
  end
42
42
 
43
- # Serializes the series
44
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
43
+ # Serializes the object
44
+ # @param [String] str
45
45
  # @return [String]
46
- def to_xml(xml)
47
- super(xml) do |xml_inner|
48
- @labels.to_xml(xml_inner) unless @labels.nil?
49
- @data.to_xml(xml_inner) unless @data.nil?
50
- xml_inner.shape :val=>@shape
51
- end
46
+ def to_xml_string(str = '')
47
+ super(str) do |str_inner|
48
+ @labels.to_xml_string(str_inner) unless @labels.nil?
49
+ @data.to_xml_string(str_inner) unless @data.nil?
50
+ str_inner << '<shape val="' << @shape.to_s << '"/>'
51
+ end
52
52
  end
53
53
 
54
-
55
- private
54
+ private
56
55
 
57
56
  # assigns the data for this series
58
57
  def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
@@ -10,7 +10,7 @@ module Axlsx
10
10
  # specifies how the perpendicular axis is crossed
11
11
  # must be one of [:ctr, :l, :r]
12
12
  # @return [Symbol]
13
- attr_reader :lblAlgn
13
+ attr_reader :lblAlgn
14
14
 
15
15
  # The offset of the labels
16
16
  # must be between a string between 0 and 1000
@@ -20,7 +20,7 @@ module Axlsx
20
20
  # regex for validating label offset
21
21
  LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)%/
22
22
 
23
- # Creates a new CatAxis object
23
+ # Creates a new CatAxis object
24
24
  # @param [Integer] axId the id of this axis. Inherited
25
25
  # @param [Integer] crossAx the id of the perpendicular axis. Inherited
26
26
  # @option options [Symbol] axPos. Inherited
@@ -28,13 +28,13 @@ module Axlsx
28
28
  # @option options [Symbol] crosses. Inherited
29
29
  # @option options [Boolean] auto
30
30
  # @option options [Symbol] lblAlgn
31
- # @option options [Integer] lblOffset
31
+ # @option options [Integer] lblOffset
32
32
  def initialize(axId, crossAx, options={})
33
33
  self.auto = 1
34
34
  self.lblAlgn = :ctr
35
35
  self.lblOffset = "100%"
36
36
  super(axId, crossAx, options)
37
- end
37
+ end
38
38
 
39
39
  # From the docs: This element specifies that this axis is a date or text axis based on the data that is used for the axis labels, not a specific choice.
40
40
  def auto=(v) Axlsx::validate_boolean(v); @auto = v; end
@@ -47,18 +47,19 @@ module Axlsx
47
47
  # must be between a string between 0 and 1000
48
48
  def lblOffset=(v) RegexValidator.validate "#{self.class}.lblOffset", LBL_OFFSET_REGEX, v; @lblOffset = v; end
49
49
 
50
- # Serializes the category axis
51
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
50
+ # Serializes the object
51
+ # @param [String] str
52
52
  # @return [String]
53
- def to_xml(xml)
54
- xml.catAx {
55
- super(xml)
56
- xml.auto :val=>@auto
57
- xml.lblAlgn :val=>@lblAlgn
58
- xml.lblOffset :val=>@lblOffset
59
- }
53
+ def to_xml_string(str = '')
54
+ str << '<c:catAx>'
55
+ super(str)
56
+ str << '<c:auto val="' << @auto.to_s << '"/>'
57
+ str << '<c:lblAlgn val="' << @lblAlgn.to_s << '"/>'
58
+ str << '<c:lblOffset val="' << @lblOffset.to_s << '"/>'
59
+ str << '</c:catAx>'
60
60
  end
61
+
61
62
  end
62
-
63
+
63
64
 
64
65
  end
@@ -11,26 +11,24 @@ module Axlsx
11
11
  data.each { |i| @list << i } if data.is_a?(SimpleTypedList)
12
12
  end
13
13
 
14
- # Serializes the category axis data
15
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
14
+ # Serializes the object
15
+ # @param [String] str
16
16
  # @return [String]
17
- def to_xml(xml)
18
- xml.cat {
19
- xml.strRef {
20
- xml.f Axlsx::cell_range(@list)
21
- xml.strCache {
22
- xml.ptCount :val=>size
23
- each_with_index do |item, index|
24
- v = item.is_a?(Cell) ? item.value : item
25
- xml.pt(:idx=>index) {
26
- xml.v v
27
- }
28
- end
29
- }
30
- }
31
- }
17
+ def to_xml_string(str = '')
18
+ str << '<c:cat>'
19
+ str << '<c:strRef>'
20
+ str << '<c:f>' << Axlsx::cell_range(@list) << '</c:f>'
21
+ str << '<c:strCache>'
22
+ str << '<c:ptCount val="' << size.to_s << '"/>'
23
+ each_with_index do |item, index|
24
+ v = item.is_a?(Cell) ? item.value.to_s : item
25
+ str << '<c:pt idx="' << index.to_s << '"><c:v>' << v << '</c:v></c:pt>'
26
+ end
27
+ str << '</c:strCache>'
28
+ str << '</c:strRef>'
29
+ str << '</c:cat>'
32
30
  end
33
31
 
34
32
  end
35
-
33
+
36
34
  end