axlsx 1.0.15 → 1.1.1

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 (184) hide show
  1. data/.yardopts +1 -0
  2. data/CHANGELOG.md +58 -2
  3. data/README.md +425 -207
  4. data/Rakefile +6 -2
  5. data/examples/axlsx.xlsx +0 -0
  6. data/examples/example.csv +1000 -0
  7. data/examples/example.rb +266 -132
  8. data/examples/example.xlsx +0 -0
  9. data/examples/example_streamed.xlsx +0 -0
  10. data/examples/no-use_autowidth.xlsx +0 -0
  11. data/examples/real_example.rb +63 -0
  12. data/examples/sample.png +0 -0
  13. data/examples/shared_strings_example.xlsx +0 -0
  14. data/lib/axlsx/content_type/content_type.rb +13 -12
  15. data/lib/axlsx/content_type/default.rb +10 -6
  16. data/lib/axlsx/content_type/override.rb +13 -8
  17. data/lib/axlsx/doc_props/app.rb +38 -41
  18. data/lib/axlsx/doc_props/core.rb +13 -17
  19. data/lib/axlsx/drawing/axis.rb +39 -19
  20. data/lib/axlsx/drawing/bar_3D_chart.rb +34 -32
  21. data/lib/axlsx/drawing/bar_series.rb +14 -14
  22. data/lib/axlsx/drawing/cat_axis.rb +16 -14
  23. data/lib/axlsx/drawing/cat_axis_data.rb +17 -18
  24. data/lib/axlsx/drawing/chart.rb +40 -41
  25. data/lib/axlsx/drawing/drawing.rb +27 -12
  26. data/lib/axlsx/drawing/graphic_frame.rb +22 -21
  27. data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
  28. data/lib/axlsx/drawing/hyperlink.rb +96 -0
  29. data/lib/axlsx/drawing/hyperlink.rb~ +64 -0
  30. data/lib/axlsx/drawing/line_3D_chart.rb +31 -28
  31. data/lib/axlsx/drawing/line_series.rb +12 -11
  32. data/lib/axlsx/drawing/marker.rb +11 -8
  33. data/lib/axlsx/drawing/named_axis_data.rb +36 -0
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +18 -16
  35. data/lib/axlsx/drawing/pic.rb +47 -33
  36. data/lib/axlsx/drawing/picture_locking.rb +22 -18
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +11 -8
  38. data/lib/axlsx/drawing/pie_series.rb +16 -12
  39. data/lib/axlsx/drawing/scaling.rb +11 -10
  40. data/lib/axlsx/drawing/scatter_chart.rb +69 -0
  41. data/lib/axlsx/drawing/scatter_series.rb +39 -0
  42. data/lib/axlsx/drawing/ser_axis.rb +11 -10
  43. data/lib/axlsx/drawing/series.rb +16 -15
  44. data/lib/axlsx/drawing/series_title.rb +15 -14
  45. data/lib/axlsx/drawing/title.rb +27 -26
  46. data/lib/axlsx/drawing/two_cell_anchor.rb +19 -20
  47. data/lib/axlsx/drawing/val_axis.rb +9 -7
  48. data/lib/axlsx/drawing/val_axis_data.rb +18 -17
  49. data/lib/axlsx/drawing/view_3D.rb +23 -20
  50. data/lib/axlsx/package.rb +117 -52
  51. data/lib/axlsx/rels/relationship.rb +27 -8
  52. data/lib/axlsx/rels/relationships.rb +9 -2
  53. data/lib/axlsx/stylesheet/border.rb +28 -23
  54. data/lib/axlsx/stylesheet/border_pr.rb +17 -15
  55. data/lib/axlsx/stylesheet/cell_alignment.rb +24 -21
  56. data/lib/axlsx/stylesheet/cell_protection.rb +11 -7
  57. data/lib/axlsx/stylesheet/cell_style.rb +9 -5
  58. data/lib/axlsx/stylesheet/color.rb +20 -14
  59. data/lib/axlsx/stylesheet/fill.rb +8 -5
  60. data/lib/axlsx/stylesheet/font.rb +22 -14
  61. data/lib/axlsx/stylesheet/gradient_fill.rb +20 -17
  62. data/lib/axlsx/stylesheet/gradient_stop.rb +10 -6
  63. data/lib/axlsx/stylesheet/num_fmt.rb +13 -6
  64. data/lib/axlsx/stylesheet/pattern_fill.rb +26 -10
  65. data/lib/axlsx/stylesheet/styles.rb +55 -41
  66. data/lib/axlsx/stylesheet/table_style.rb +10 -4
  67. data/lib/axlsx/stylesheet/table_style_element.rb +11 -7
  68. data/lib/axlsx/stylesheet/table_styles.rb +12 -8
  69. data/lib/axlsx/stylesheet/xf.rb +30 -25
  70. data/lib/axlsx/util/cbf.rb +69 -33
  71. data/lib/axlsx/util/constants.rb +39 -20
  72. data/lib/axlsx/util/doc/_index.html +84 -0
  73. data/lib/axlsx/util/doc/class_list.html +47 -0
  74. data/lib/axlsx/util/doc/css/common.css +1 -0
  75. data/lib/axlsx/util/doc/css/full_list.css +55 -0
  76. data/lib/axlsx/util/doc/css/style.css +322 -0
  77. data/lib/axlsx/util/doc/file_list.html +46 -0
  78. data/lib/axlsx/util/doc/frames.html +13 -0
  79. data/lib/axlsx/util/doc/index.html +84 -0
  80. data/lib/axlsx/util/doc/js/app.js +205 -0
  81. data/lib/axlsx/util/doc/js/full_list.js +173 -0
  82. data/lib/axlsx/util/doc/js/jquery.js +16 -0
  83. data/lib/axlsx/util/doc/method_list.html +46 -0
  84. data/lib/axlsx/util/doc/top-level-namespace.html +95 -0
  85. data/lib/axlsx/util/font_tables.rb~ +0 -0
  86. data/lib/axlsx/util/ms_off_crypto.rb +10 -10
  87. data/lib/axlsx/util/parser.rb +1 -0
  88. data/lib/axlsx/util/simple_typed_list.rb +20 -10
  89. data/lib/axlsx/util/storage.rb +1 -1
  90. data/lib/axlsx/util/validators.rb +23 -7
  91. data/lib/axlsx/version.rb +5 -2
  92. data/lib/axlsx/workbook/shared_strings_table.rb +68 -0
  93. data/lib/axlsx/workbook/shared_strings_table.rb~ +69 -0
  94. data/lib/axlsx/workbook/workbook.rb +82 -26
  95. data/lib/axlsx/workbook/worksheet/cell.rb +166 -130
  96. data/lib/axlsx/workbook/worksheet/col.rb +114 -0
  97. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  98. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
  99. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
  100. data/lib/axlsx/workbook/worksheet/row.rb +53 -21
  101. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  102. data/lib/axlsx/workbook/worksheet/table.rb +96 -0
  103. data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
  104. data/lib/axlsx/workbook/worksheet/worksheet.rb +275 -124
  105. data/lib/axlsx.rb +41 -14
  106. data/lib/schema/dc.xsd +5 -5
  107. data/lib/schema/dcmitype.xsd +5 -3
  108. data/lib/schema/dcterms.xsd +15 -15
  109. data/lib/schema/opc-coreProperties.xsd +6 -2
  110. data/lib/schema/xml.xsd +7 -8
  111. data/test/benchmark.rb +73 -0
  112. data/test/content_type/tc_content_type.rb +31 -31
  113. data/test/content_type/tc_default.rb +9 -22
  114. data/test/content_type/tc_override.rb +8 -21
  115. data/test/doc_props/tc_app.rb +2 -8
  116. data/test/doc_props/tc_core.rb +6 -7
  117. data/test/drawing/tc_axis.rb +7 -3
  118. data/test/drawing/tc_bar_3D_chart.rb +6 -7
  119. data/test/drawing/tc_bar_series.rb +4 -5
  120. data/test/drawing/tc_cat_axis.rb +2 -3
  121. data/test/drawing/tc_cat_axis_data.rb +2 -3
  122. data/test/drawing/tc_chart.rb +13 -14
  123. data/test/drawing/tc_drawing.rb +7 -8
  124. data/test/drawing/tc_graphic_frame.rb +3 -4
  125. data/test/drawing/tc_hyperlink.rb +69 -0
  126. data/test/drawing/tc_line_3d_chart.rb +5 -6
  127. data/test/drawing/tc_line_series.rb +3 -4
  128. data/test/drawing/tc_marker.rb +3 -4
  129. data/test/drawing/tc_one_cell_anchor.rb +6 -7
  130. data/test/drawing/tc_pic.rb +13 -8
  131. data/test/drawing/tc_picture_locking.rb +2 -3
  132. data/test/drawing/tc_pie_3D_chart.rb +5 -6
  133. data/test/drawing/tc_pie_series.rb +4 -5
  134. data/test/drawing/tc_scaling.rb +3 -4
  135. data/test/drawing/tc_scatter_chart.rb +43 -0
  136. data/test/drawing/tc_scatter_series.rb +20 -0
  137. data/test/drawing/tc_ser_axis.rb +2 -3
  138. data/test/drawing/tc_series.rb +4 -5
  139. data/test/drawing/tc_series_title.rb +4 -5
  140. data/test/drawing/tc_title.rb +4 -5
  141. data/test/drawing/tc_two_cell_anchor.rb +4 -5
  142. data/test/drawing/tc_val_axis.rb +2 -3
  143. data/test/drawing/tc_val_axis_data.rb +2 -3
  144. data/test/drawing/tc_view_3D.rb +6 -7
  145. data/test/profile.rb +34 -0
  146. data/test/rels/tc_relationship.rb +10 -6
  147. data/test/rels/tc_relationships.rb +4 -5
  148. data/test/stylesheet/tc_border.rb +3 -4
  149. data/test/stylesheet/tc_border_pr.rb +3 -4
  150. data/test/stylesheet/tc_cell_alignment.rb +10 -6
  151. data/test/stylesheet/tc_cell_protection.rb +2 -3
  152. data/test/stylesheet/tc_cell_style.rb +2 -3
  153. data/test/stylesheet/tc_color.rb +2 -3
  154. data/test/stylesheet/tc_fill.rb +1 -2
  155. data/test/stylesheet/tc_font.rb +12 -5
  156. data/test/stylesheet/tc_gradient_fill.rb +1 -2
  157. data/test/stylesheet/tc_gradient_stop.rb +1 -2
  158. data/test/stylesheet/tc_num_fmt.rb +1 -2
  159. data/test/stylesheet/tc_pattern_fill.rb +3 -4
  160. data/test/stylesheet/tc_styles.rb +31 -6
  161. data/test/stylesheet/tc_table_style.rb +2 -3
  162. data/test/stylesheet/tc_table_style_element.rb +2 -3
  163. data/test/stylesheet/tc_table_styles.rb +3 -4
  164. data/test/stylesheet/tc_xf.rb +16 -17
  165. data/test/tc_axlsx.rb +39 -0
  166. data/test/tc_helper.rb +3 -0
  167. data/test/tc_package.rb +43 -9
  168. data/test/util/tc_simple_typed_list.rb +8 -9
  169. data/test/util/tc_validators.rb +7 -8
  170. data/test/workbook/tc_shared_strings_table.rb +38 -0
  171. data/test/workbook/tc_workbook.rb +32 -6
  172. data/test/workbook/worksheet/table/tc_table.rb +71 -0
  173. data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
  174. data/test/workbook/worksheet/tc_cell.rb +80 -13
  175. data/test/workbook/worksheet/tc_col.rb +59 -0
  176. data/test/workbook/worksheet/tc_col.rb~ +10 -0
  177. data/test/workbook/worksheet/tc_date_time_converter.rb +132 -0
  178. data/test/workbook/worksheet/tc_page_margins.rb +97 -0
  179. data/test/workbook/worksheet/tc_row.rb +54 -4
  180. data/test/workbook/worksheet/tc_worksheet.rb +205 -31
  181. metadata +78 -84
  182. data/examples/example.rb~ +0 -112
  183. data/test/drawing/tc_line_series.tc~ +0 -34
  184. 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
  # App represents the app.xml document. The attributes for this object are primarily managed by the application the end user uses to edit the document. None of the attributes are required to serialize a valid xlsx object.
4
4
  # @see shared-documentPropertiesExtended.xsd
@@ -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
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
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # The core object for the package.
3
4
  # @note Packages manage their own core object.
@@ -6,29 +7,24 @@ module Axlsx
6
7
  # The author of the document. By default this is 'axlsx'
7
8
  # @return [String]
8
9
  attr_accessor :creator
9
-
10
+
10
11
  # Creates a new Core object.
11
12
  # @option options [String] creator
12
13
  def initialize(options={})
13
- @creator = options[:creator] || 'axlsx'
14
+ @creator = options[:creator] || 'axlsx'
14
15
  end
15
16
 
16
- # 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
17
18
  # @return [String]
18
- def to_xml()
19
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
20
- xml.send('cp:coreProperties',
21
- :"xmlns:cp" => CORE_NS,
22
- :'xmlns:dc' => CORE_NS_DC,
23
- :'xmlns:dcmitype'=>CORE_NS_DCMIT,
24
- :'xmlns:dcterms'=>CORE_NS_DCT,
25
- :'xmlns:xsi'=>CORE_NS_XSI) {
26
- xml['dc'].creator self.creator
27
- xml['dcterms'].created Time.now.strftime('%Y-%m-%dT%H:%M:%S'), :'xsi:type'=>"dcterms:W3CDTF"
28
- xml['cp'].revision 0
29
- }
30
- end
31
- builder.to_xml
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>'
32
28
  end
33
29
  end
34
30
  end
@@ -1,8 +1,9 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # the access class defines common properties and values for a chart axis.
3
4
  class Axis
4
5
 
5
- # the id of the axis.
6
+ # the id of the axis.
6
7
  # @return [Integer]
7
8
  attr_reader :axId
8
9
 
@@ -14,7 +15,7 @@ module Axlsx
14
15
  # @see Scaling
15
16
  # @return [Scaling]
16
17
  attr_reader :scaling
17
-
18
+
18
19
  # The position of the axis
19
20
  # must be one of [:l, :r, :t, :b]
20
21
  # @return [Symbol]
@@ -33,7 +34,11 @@ module Axlsx
33
34
  # specifies how the perpendicular axis is crossed
34
35
  # must be one of [:autoZero, :min, :max]
35
36
  # @return [Symbol]
36
- 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
37
42
 
38
43
  # Creates an Axis object
39
44
  # @param [Integer] axId the id of this axis
@@ -48,11 +53,12 @@ module Axlsx
48
53
  @axId = axId
49
54
  @crossAx = crossAx
50
55
  @format_code = "General"
51
- @scaling = Scaling.new(:orientation=>:minMax)
56
+ @scaling = Scaling.new(:orientation=>:minMax)
52
57
  self.axPos = :b
53
58
  self.tickLblPos = :nextTo
54
59
  self.format_code = "General"
55
60
  self.crosses = :autoZero
61
+ self.gridlines = true
56
62
  options.each do |o|
57
63
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
58
64
  end
@@ -69,25 +75,39 @@ module Axlsx
69
75
  # default :General
70
76
  def format_code=(v) Axlsx::validate_string(v); @format_code = v; end
71
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
+
72
82
  # specifies how the perpendicular axis is crossed
73
83
  # must be one of [:autoZero, :min, :max]
74
84
  def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end
75
85
 
76
- # Serializes the common axis
77
- # @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
78
89
  # @return [String]
79
- def to_xml(xml)
80
- xml.axId :val=>@axId
81
- @scaling.to_xml(xml)
82
- xml.delete :val=>0
83
- xml.axPos :val=>@axPos
84
- xml.majorGridlines
85
- xml.numFmt :formatCode => @format_code, :sourceLinked=>"1"
86
- xml.majorTickMark :val=>"none"
87
- xml.minorTickMark :val=>"none"
88
- xml.tickLblPos :val=>@tickLblPos
89
- xml.crossAx :val=>@crossAx
90
- xml.crosses :val=>@crosses
91
- 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
+
92
112
  end
93
113
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
 
3
4
  # The Bar3DChart is a three dimentional barchart (who would have guessed?) that you can add to your worksheet.
@@ -40,7 +41,7 @@ module Axlsx
40
41
 
41
42
  # validation regex for gap amount percent
42
43
  GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
43
-
44
+
44
45
  # Creates a new bar chart object
45
46
  # @param [GraphicFrame] frame The workbook that owns this chart.
46
47
  # @option options [Cell, String] title
@@ -66,14 +67,14 @@ module Axlsx
66
67
  @valAxId = rand(8 ** 8)
67
68
  @catAxis = CatAxis.new(@catAxId, @valAxId)
68
69
  @valAxis = ValAxis.new(@valAxId, @catAxId, :tickLblPos => :low)
69
- super(frame, options)
70
+ super(frame, options)
70
71
  @series_type = BarSeries
71
72
  @view3D = View3D.new({:rAngAx=>1}.merge(options))
72
73
  end
73
74
 
74
75
  # The direction of the bars in the chart
75
76
  # must be one of [:bar, :col]
76
- def barDir=(v)
77
+ def barDir=(v)
77
78
  RestrictionValidator.validate "Bar3DChart.barDir", [:bar, :col], v
78
79
  @barDir = v
79
80
  end
@@ -99,38 +100,39 @@ module Axlsx
99
100
 
100
101
  # The shabe of the bars or columns
101
102
  # must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax]
102
- def shape=(v)
103
+ def shape=(v)
103
104
  RestrictionValidator.validate "Bar3DChart.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v
104
105
  @shape = v
105
106
  end
106
-
107
- # Serializes the bar chart
107
+
108
+ # Serializes the object
109
+ # @param [String] str
108
110
  # @return [String]
109
- def to_xml
110
- super() do |xml|
111
- xml.bar3DChart {
112
- xml.barDir :val => barDir
113
- xml.grouping :val=>grouping
114
- xml.varyColors :val=>1
115
- @series.each { |ser| ser.to_xml(xml) }
116
- xml.dLbls {
117
- xml.showLegendKey :val=>0
118
- xml.showVal :val=>0
119
- xml.showCatName :val=>0
120
- xml.showSerName :val=>0
121
- xml.showPercent :val=>0
122
- xml.showBubbleSize :val=>0
123
- }
124
- xml.gapWidth :val=>@gapWidth unless @gapWidth.nil?
125
- xml.gapDepth :val=>@gapDepth unless @gapDepth.nil?
126
- xml.shape :val=>@shape unless @shape.nil?
127
- xml.axId :val=>@catAxId
128
- xml.axId :val=>@valAxId
129
- xml.axId :val=>0
130
- }
131
- @catAxis.to_xml(xml)
132
- @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
133
135
  end
134
- end
135
- end
136
+ end
137
+ end
136
138
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # A BarSeries defines the title, data and labels for bar charts
3
4
  # @note The recommended way to manage series is to use Chart#add_series
@@ -5,8 +6,8 @@ module Axlsx
5
6
  # @see Chart#add_series
6
7
  class BarSeries < Series
7
8
 
8
-
9
- # The data for this series.
9
+
10
+ # The data for this series.
10
11
  # @return [Array, SimpleTypedList]
11
12
  attr_reader :data
12
13
 
@@ -30,28 +31,27 @@ module Axlsx
30
31
  super(chart, options)
31
32
  self.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
32
33
  self.data = ValAxisData.new(options[:data]) unless options[:data].nil?
33
- end
34
+ end
34
35
 
35
36
  # The shabe of the bars or columns
36
37
  # must be one of [:percentStacked, :clustered, :standard, :stacked]
37
- def shape=(v)
38
+ def shape=(v)
38
39
  RestrictionValidator.validate "BarSeries.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v
39
40
  @shape = v
40
41
  end
41
42
 
42
- # Serializes the series
43
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
43
+ # Serializes the object
44
+ # @param [String] str
44
45
  # @return [String]
45
- def to_xml(xml)
46
- super(xml) do |xml_inner|
47
- @labels.to_xml(xml_inner) unless @labels.nil?
48
- @data.to_xml(xml_inner) unless @data.nil?
49
- xml_inner.shape :val=>@shape
50
- 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
51
52
  end
52
53
 
53
-
54
- private
54
+ private
55
55
 
56
56
  # assigns the data for this series
57
57
  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
  #A CatAxis object defines a chart category axis
3
4
  class CatAxis < Axis
@@ -9,7 +10,7 @@ module Axlsx
9
10
  # specifies how the perpendicular axis is crossed
10
11
  # must be one of [:ctr, :l, :r]
11
12
  # @return [Symbol]
12
- attr_reader :lblAlgn
13
+ attr_reader :lblAlgn
13
14
 
14
15
  # The offset of the labels
15
16
  # must be between a string between 0 and 1000
@@ -19,7 +20,7 @@ module Axlsx
19
20
  # regex for validating label offset
20
21
  LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)%/
21
22
 
22
- # Creates a new CatAxis object
23
+ # Creates a new CatAxis object
23
24
  # @param [Integer] axId the id of this axis. Inherited
24
25
  # @param [Integer] crossAx the id of the perpendicular axis. Inherited
25
26
  # @option options [Symbol] axPos. Inherited
@@ -27,13 +28,13 @@ module Axlsx
27
28
  # @option options [Symbol] crosses. Inherited
28
29
  # @option options [Boolean] auto
29
30
  # @option options [Symbol] lblAlgn
30
- # @option options [Integer] lblOffset
31
+ # @option options [Integer] lblOffset
31
32
  def initialize(axId, crossAx, options={})
32
33
  self.auto = 1
33
34
  self.lblAlgn = :ctr
34
35
  self.lblOffset = "100%"
35
36
  super(axId, crossAx, options)
36
- end
37
+ end
37
38
 
38
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.
39
40
  def auto=(v) Axlsx::validate_boolean(v); @auto = v; end
@@ -46,18 +47,19 @@ module Axlsx
46
47
  # must be between a string between 0 and 1000
47
48
  def lblOffset=(v) RegexValidator.validate "#{self.class}.lblOffset", LBL_OFFSET_REGEX, v; @lblOffset = v; end
48
49
 
49
- # Serializes the category axis
50
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
50
+ # Serializes the object
51
+ # @param [String] str
51
52
  # @return [String]
52
- def to_xml(xml)
53
- xml.catAx {
54
- super(xml)
55
- xml.auto :val=>@auto
56
- xml.lblAlgn :val=>@lblAlgn
57
- xml.lblOffset :val=>@lblOffset
58
- }
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>'
59
60
  end
61
+
60
62
  end
61
-
63
+
62
64
 
63
65
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # The CatAxisData class serializes the category axis data for a chart
3
4
  class CatAxisData < SimpleTypedList
@@ -10,26 +11,24 @@ module Axlsx
10
11
  data.each { |i| @list << i } if data.is_a?(SimpleTypedList)
11
12
  end
12
13
 
13
- # Serializes the category axis data
14
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
14
+ # Serializes the object
15
+ # @param [String] str
15
16
  # @return [String]
16
- def to_xml(xml)
17
- xml.cat {
18
- xml.strRef {
19
- xml.f Axlsx::cell_range(@list)
20
- xml.strCache {
21
- xml.ptCount :val=>size
22
- each_with_index do |item, index|
23
- v = item.is_a?(Cell) ? item.value : item
24
- xml.pt(:idx=>index) {
25
- xml.v v
26
- }
27
- end
28
- }
29
- }
30
- }
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>'
31
30
  end
32
31
 
33
32
  end
34
-
33
+
35
34
  end