axlsx 1.0.16 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. data/.yardopts +1 -0
  2. data/CHANGELOG.md +18 -3
  3. data/README.md +189 -55
  4. data/examples/example.csv +1000 -0
  5. data/examples/example.rb +264 -142
  6. data/examples/example.xlsx +0 -0
  7. data/examples/example_streamed.xlsx +0 -0
  8. data/examples/no-use_autowidth.xlsx +0 -0
  9. data/examples/shared_strings_example.xlsx +0 -0
  10. data/lib/axlsx/content_type/content_type.rb +13 -12
  11. data/lib/axlsx/content_type/default.rb +10 -6
  12. data/lib/axlsx/content_type/override.rb +13 -8
  13. data/lib/axlsx/doc_props/app.rb +38 -41
  14. data/lib/axlsx/doc_props/core.rb +13 -17
  15. data/lib/axlsx/drawing/axis.rb +39 -19
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +34 -32
  17. data/lib/axlsx/drawing/bar_series.rb +14 -14
  18. data/lib/axlsx/drawing/cat_axis.rb +16 -14
  19. data/lib/axlsx/drawing/cat_axis_data.rb +17 -18
  20. data/lib/axlsx/drawing/chart.rb +40 -41
  21. data/lib/axlsx/drawing/drawing.rb +16 -12
  22. data/lib/axlsx/drawing/graphic_frame.rb +22 -21
  23. data/lib/axlsx/drawing/hyperlink.rb +13 -12
  24. data/lib/axlsx/drawing/line_3D_chart.rb +31 -28
  25. data/lib/axlsx/drawing/line_series.rb +12 -11
  26. data/lib/axlsx/drawing/marker.rb +11 -8
  27. data/lib/axlsx/drawing/named_axis_data.rb +36 -0
  28. data/lib/axlsx/drawing/one_cell_anchor.rb +18 -16
  29. data/lib/axlsx/drawing/pic.rb +26 -38
  30. data/lib/axlsx/drawing/picture_locking.rb +22 -18
  31. data/lib/axlsx/drawing/pie_3D_chart.rb +11 -8
  32. data/lib/axlsx/drawing/pie_series.rb +16 -12
  33. data/lib/axlsx/drawing/scaling.rb +11 -10
  34. data/lib/axlsx/drawing/scatter_chart.rb +69 -0
  35. data/lib/axlsx/drawing/scatter_series.rb +39 -0
  36. data/lib/axlsx/drawing/ser_axis.rb +11 -10
  37. data/lib/axlsx/drawing/series.rb +16 -15
  38. data/lib/axlsx/drawing/series_title.rb +15 -14
  39. data/lib/axlsx/drawing/title.rb +27 -26
  40. data/lib/axlsx/drawing/two_cell_anchor.rb +19 -20
  41. data/lib/axlsx/drawing/val_axis.rb +9 -7
  42. data/lib/axlsx/drawing/val_axis_data.rb +18 -17
  43. data/lib/axlsx/drawing/view_3D.rb +23 -20
  44. data/lib/axlsx/package.rb +116 -51
  45. data/lib/axlsx/rels/relationship.rb +12 -8
  46. data/lib/axlsx/rels/relationships.rb +8 -1
  47. data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
  48. data/lib/axlsx/stylesheet/border.rb +28 -23
  49. data/lib/axlsx/stylesheet/border_pr.rb +17 -15
  50. data/lib/axlsx/stylesheet/cell_alignment.rb +24 -21
  51. data/lib/axlsx/stylesheet/cell_protection.rb +11 -7
  52. data/lib/axlsx/stylesheet/cell_style.rb +9 -5
  53. data/lib/axlsx/stylesheet/color.rb +21 -14
  54. data/lib/axlsx/stylesheet/fill.rb +8 -5
  55. data/lib/axlsx/stylesheet/font.rb +22 -14
  56. data/lib/axlsx/stylesheet/gradient_fill.rb +20 -17
  57. data/lib/axlsx/stylesheet/gradient_stop.rb +10 -6
  58. data/lib/axlsx/stylesheet/num_fmt.rb +13 -6
  59. data/lib/axlsx/stylesheet/pattern_fill.rb +26 -10
  60. data/lib/axlsx/stylesheet/styles.rb +53 -41
  61. data/lib/axlsx/stylesheet/table_style.rb +10 -4
  62. data/lib/axlsx/stylesheet/table_style_element.rb +11 -7
  63. data/lib/axlsx/stylesheet/table_styles.rb +12 -8
  64. data/lib/axlsx/stylesheet/xf.rb +30 -25
  65. data/lib/axlsx/util/cbf.rb +1 -0
  66. data/lib/axlsx/util/constants.rb +27 -14
  67. data/lib/axlsx/util/ms_off_crypto.rb +1 -1
  68. data/lib/axlsx/util/parser.rb +1 -0
  69. data/lib/axlsx/util/simple_typed_list.rb +20 -10
  70. data/lib/axlsx/util/storage.rb +1 -0
  71. data/lib/axlsx/util/validators.rb +23 -7
  72. data/lib/axlsx/version.rb +2 -1
  73. data/lib/axlsx/workbook/shared_strings_table.rb +69 -0
  74. data/lib/axlsx/workbook/shared_strings_table.rb~ +69 -0
  75. data/lib/axlsx/workbook/workbook.rb +81 -35
  76. data/lib/axlsx/workbook/worksheet/cell.rb +172 -117
  77. data/lib/axlsx/workbook/worksheet/col.rb +114 -0
  78. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  79. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +29 -0
  80. data/lib/axlsx/workbook/worksheet/page_margins.rb +97 -0
  81. data/lib/axlsx/workbook/worksheet/row.rb +53 -21
  82. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  83. data/lib/axlsx/workbook/worksheet/table.rb +96 -0
  84. data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
  85. data/lib/axlsx/workbook/worksheet/worksheet.rb +269 -121
  86. data/lib/axlsx.rb +41 -14
  87. data/lib/schema/dc.xsd +5 -5
  88. data/lib/schema/dcmitype.xsd +5 -3
  89. data/lib/schema/dcterms.xsd +15 -15
  90. data/lib/schema/opc-coreProperties.xsd +6 -2
  91. data/lib/schema/xml.xsd +7 -8
  92. data/test/#benchmark.txt# +7 -0
  93. data/test/#tc_helper.rb# +3 -0
  94. data/test/benchmark.rb +81 -0
  95. data/test/benchmark.rb~ +0 -0
  96. data/test/benchmark.txt +6 -0
  97. data/test/benchmark.txt~ +6 -0
  98. data/test/content_type/tc_content_type.rb +31 -31
  99. data/test/content_type/tc_default.rb +9 -22
  100. data/test/content_type/tc_override.rb +8 -21
  101. data/test/doc_props/tc_app.rb +2 -8
  102. data/test/doc_props/tc_core.rb +6 -7
  103. data/test/drawing/tc_axis.rb +7 -3
  104. data/test/drawing/tc_bar_3D_chart.rb +6 -7
  105. data/test/drawing/tc_bar_series.rb +4 -5
  106. data/test/drawing/tc_cat_axis.rb +2 -3
  107. data/test/drawing/tc_cat_axis_data.rb +2 -3
  108. data/test/drawing/tc_chart.rb +13 -14
  109. data/test/drawing/tc_drawing.rb +7 -8
  110. data/test/drawing/tc_graphic_frame.rb +3 -4
  111. data/test/drawing/tc_hyperlink.rb +2 -3
  112. data/test/drawing/tc_line_3d_chart.rb +5 -6
  113. data/test/drawing/tc_line_series.rb +3 -4
  114. data/test/drawing/tc_marker.rb +3 -4
  115. data/test/drawing/tc_one_cell_anchor.rb +6 -7
  116. data/test/drawing/tc_pic.rb +8 -9
  117. data/test/drawing/tc_picture_locking.rb +2 -3
  118. data/test/drawing/tc_pie_3D_chart.rb +5 -6
  119. data/test/drawing/tc_pie_series.rb +4 -5
  120. data/test/drawing/tc_scaling.rb +3 -4
  121. data/test/drawing/tc_scatter_chart.rb +43 -0
  122. data/test/drawing/tc_scatter_series.rb +20 -0
  123. data/test/drawing/tc_ser_axis.rb +2 -3
  124. data/test/drawing/tc_series.rb +4 -5
  125. data/test/drawing/tc_series_title.rb +4 -5
  126. data/test/drawing/tc_title.rb +4 -5
  127. data/test/drawing/tc_two_cell_anchor.rb +4 -5
  128. data/test/drawing/tc_val_axis.rb +2 -3
  129. data/test/drawing/tc_val_axis_data.rb +2 -3
  130. data/test/drawing/tc_view_3D.rb +6 -7
  131. data/test/example.csv +1000 -0
  132. data/test/example.xlsx +0 -0
  133. data/test/example_streamed.xlsx +0 -0
  134. data/test/profile.rb +33 -0
  135. data/test/rels/tc_relationship.rb +5 -6
  136. data/test/rels/tc_relationships.rb +4 -5
  137. data/test/stylesheet/tc_border.rb +3 -4
  138. data/test/stylesheet/tc_border_pr.rb +3 -4
  139. data/test/stylesheet/tc_cell_alignment.rb +10 -6
  140. data/test/stylesheet/tc_cell_protection.rb +2 -3
  141. data/test/stylesheet/tc_cell_style.rb +2 -3
  142. data/test/stylesheet/tc_color.rb +2 -3
  143. data/test/stylesheet/tc_fill.rb +1 -2
  144. data/test/stylesheet/tc_font.rb +12 -5
  145. data/test/stylesheet/tc_gradient_fill.rb +1 -2
  146. data/test/stylesheet/tc_gradient_stop.rb +1 -2
  147. data/test/stylesheet/tc_num_fmt.rb +1 -2
  148. data/test/stylesheet/tc_pattern_fill.rb +3 -4
  149. data/test/stylesheet/tc_styles.rb +16 -6
  150. data/test/stylesheet/tc_table_style.rb +2 -3
  151. data/test/stylesheet/tc_table_style_element.rb +2 -3
  152. data/test/stylesheet/tc_table_styles.rb +3 -4
  153. data/test/stylesheet/tc_xf.rb +16 -17
  154. data/test/tc_axlsx.rb +39 -0
  155. data/test/tc_axlsx.rb~ +0 -0
  156. data/test/tc_helper.rb +3 -0
  157. data/test/tc_helper.rb~ +3 -0
  158. data/test/tc_package.rb +43 -9
  159. data/test/util/tc_simple_typed_list.rb +8 -9
  160. data/test/util/tc_validators.rb +7 -8
  161. data/test/workbook/tc_shared_strings_table.rb +38 -0
  162. data/test/workbook/tc_workbook.rb +32 -6
  163. data/test/workbook/worksheet/table/tc_table.rb +71 -0
  164. data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
  165. data/test/workbook/worksheet/tc_cell.rb +70 -13
  166. data/test/workbook/worksheet/tc_col.rb +59 -0
  167. data/test/workbook/worksheet/tc_col.rb~ +10 -0
  168. data/test/workbook/worksheet/tc_date_time_converter.rb +126 -0
  169. data/test/workbook/worksheet/tc_page_margins.rb +97 -0
  170. data/test/workbook/worksheet/tc_row.rb +54 -4
  171. data/test/workbook/worksheet/tc_worksheet.rb +191 -31
  172. metadata +162 -109
  173. data/test/drawing/tc_hyperlink.rb~ +0 -71
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # A PatternFill is the pattern and solid fill styling for a cell.
3
4
  # @note The recommended way to manage styles is with Styles#add_style
@@ -6,15 +7,15 @@ module Axlsx
6
7
 
7
8
  # The color to use for the the background in solid fills.
8
9
  # @return [Color]
9
- attr_reader :fgColor
10
+ attr_reader :fgColor
10
11
 
11
12
  # The color to use for the background of the fill when the type is not solid.
12
13
  # @return [Color]
13
14
  attr_reader :bgColor
14
15
 
15
16
  # The pattern type to use
16
- # @note
17
- # patternType must be one of
17
+ # @note
18
+ # patternType must be one of
18
19
  # :none
19
20
  # :solid
20
21
  # :mediumGray
@@ -52,15 +53,30 @@ module Axlsx
52
53
  # @see bgColor
53
54
  def bgColor=(v) DataTypeValidator.validate "PatternFill.bgColor", Color, v; @bgColor=v end
54
55
  # @see patternType
55
- def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end
56
+ def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end
56
57
 
57
- # Serializes the pattern fill
58
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
58
+ # Serializes the object
59
+ # @param [String] str
59
60
  # @return [String]
60
- def to_xml(xml)
61
- xml.patternFill(:patternType => self.patternType) {
62
- self.instance_values.reject { |k,v| k.to_sym == :patternType }.each { |k,v| xml.send(k, v.instance_values) }
63
- }
61
+ def to_xml_string(str = '')
62
+ str << '<patternFill patternType="' << patternType.to_s << '">'
63
+ if fgColor.is_a?(Color)
64
+ str << "<fgColor "
65
+ fgColor.instance_values.each do |key, value|
66
+ str << key.to_s << '="' << value.to_s << '" '
67
+ end
68
+ str << "/>"
69
+ end
70
+
71
+ if bgColor.is_a?(Color)
72
+ str << "<bgColor "
73
+ bgColor.instance_values.each do |key, value|
74
+ str << key.to_s << '="' << value.to_s << '" '
75
+ end
76
+ str << "/>"
77
+ end
78
+ str << '</patternFill>'
64
79
  end
80
+
65
81
  end
66
82
  end
@@ -1,4 +1,4 @@
1
- # -*- coding: utf-8 -*-
1
+ # encoding: UTF-8
2
2
  module Axlsx
3
3
  require 'axlsx/stylesheet/border.rb'
4
4
  require 'axlsx/stylesheet/border_pr.rb'
@@ -120,25 +120,26 @@ module Axlsx
120
120
  end
121
121
 
122
122
  # Drastically simplifies style creation and management.
123
- # @return [Integer]
123
+ # @return [Integer]
124
124
  # @option options [String] fg_color The text color
125
125
  # @option options [Integer] sz The text size
126
126
  # @option options [Boolean] b Indicates if the text should be bold
127
127
  # @option options [Boolean] i Indicates if the text should be italicised
128
+ # @option options [Boolean] u Indicates if the text should be underlined
128
129
  # @option options [Boolean] strike Indicates if the text should be rendered with a strikethrough
129
130
  # @option options [Boolean] strike Indicates if the text should be rendered with a shadow
130
131
  # @option options [Integer] charset The character set to use.
131
132
  # @option options [Integer] family The font family to use.
132
- # @option options [String] name The name of the font to use
133
+ # @option options [String] font_name The name of the font to use
133
134
  # @option options [Integer] num_fmt The number format to apply
134
135
  # @option options [String] format_code The formatting to apply. If this is specified, num_fmt is ignored.
135
- # @option options [Integer] border The border style to use.
136
+ # @option options [Integer] border The border style to use.
136
137
  # @option options [String] bg_color The background color to apply to the cell
137
138
  # @option options [Boolean] hidden Indicates if the cell should be hidden
138
139
  # @option options [Boolean] locked Indicates if the cell should be locked
139
140
  # @option options [Hash] alignment A hash defining any of the attributes used in CellAlignment
140
141
  # @see CellAlignment
141
- #
142
+ #
142
143
  # @example You Got Style
143
144
  # require "rubygems" # if that is your preferred way to manage gems!
144
145
  # require "axlsx"
@@ -147,7 +148,7 @@ module Axlsx
147
148
  # ws = p.workbook.add_worksheet
148
149
  #
149
150
  # # black text on a white background at 14pt with thin borders!
150
- # title = ws.style.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=>Axlsx::STYLE_THIN_BORDER
151
+ # title = ws.style.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
151
152
  #
152
153
  # ws.add_row :values => ["Least Popular Pets"]
153
154
  # ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
@@ -164,15 +165,15 @@ module Axlsx
164
165
  # ws = p.workbook.add_worksheet
165
166
  #
166
167
  # # define your styles
167
- # title = ws.style.add_style(:bg_color => "FFFF0000",
168
+ # title = ws.style.add_style(:bg_color => "FFFF0000",
168
169
  # :fg_color=>"#FF000000",
169
- # :border=>Axlsx::STYLE_THIN_BORDER,
170
+ # :border=>Axlsx::STYLE_THIN_BORDER,
170
171
  # :alignment=>{:horizontal => :center})
171
172
  #
172
173
  # date_time = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS,
173
174
  # :border=>Axlsx::STYLE_THIN_BORDER)
174
175
  #
175
- # percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
176
+ # percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
176
177
  # :border=>Axlsx::STYLE_THIN_BORDER)
177
178
  #
178
179
  # currency = ws.style.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0",
@@ -189,7 +190,7 @@ module Axlsx
189
190
  # f = File.open('example_you_got_style.xlsx', 'w')
190
191
  # p.serialize(f)
191
192
  def add_style(options={})
192
-
193
+
193
194
  numFmtId = if options[:format_code]
194
195
  n = @numFmts.map{ |f| f.numFmtId }.max + 1
195
196
  numFmts << NumFmt.new(:numFmtId => n, :formatCode=> options[:format_code])
@@ -197,82 +198,93 @@ module Axlsx
197
198
  else
198
199
  options[:num_fmt] || 0
199
200
  end
200
-
201
+
201
202
  borderId = options[:border] || 0
203
+
204
+ if borderId.is_a?(Hash)
205
+ raise ArgumentError, "border hash definitions must include both style and color" unless borderId.keys.include?(:style) && borderId.keys.include?(:color)
206
+
207
+ s = borderId.delete :style
208
+ c = borderId.delete :color
209
+ border = Border.new
210
+ [:left, :right, :top, :bottom].each {|pr| border.prs << BorderPr.new(:name => pr, :style=>s, :color => Color.new(:rgb => c))}
211
+ borderId = self.borders << border
212
+ end
213
+
202
214
  raise ArgumentError, "Invalid borderId" unless borderId < borders.size
203
-
215
+
204
216
  fill = if options[:bg_color]
205
217
  color = Color.new(:rgb=>options[:bg_color])
206
218
  pattern = PatternFill.new(:patternType =>:solid, :fgColor=>color)
207
- fills << Fill.new(pattern)
219
+ fills << Fill.new(pattern)
208
220
  else
209
221
  0
210
222
  end
211
-
212
- fontId = if (options.values_at(:fg_color, :sz, :b, :i, :strike, :outline, :shadow, :charset, :family, :font_name).length)
223
+
224
+ fontId = if (options.values_at(:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name).length)
213
225
  font = Font.new()
214
- [:b, :i, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? }
226
+ [:b, :i, :u, :strike, :outline, :shadow, :charset, :family, :sz].each { |k| font.send("#{k}=", options[k]) unless options[k].nil? }
215
227
  font.color = Color.new(:rgb => options[:fg_color]) unless options[:fg_color].nil?
216
228
  font.name = options[:font_name] unless options[:font_name].nil?
217
229
  fonts << font
218
230
  else
219
- 0
231
+ 0
220
232
  end
221
-
233
+
222
234
  applyProtection = (options[:hidden] || options[:locked]) ? 1 : 0
223
-
235
+
224
236
  xf = Xf.new(:fillId => fill, :fontId=>fontId, :applyFill=>1, :applyFont=>1, :numFmtId=>numFmtId, :borderId=>borderId, :applyProtection=>applyProtection)
225
237
 
226
238
  xf.applyNumberFormat = true if xf.numFmtId > 0
227
-
239
+ xf.applyBorder = true if borderId > 0
240
+
228
241
  if options[:alignment]
229
242
  xf.alignment = CellAlignment.new(options[:alignment])
243
+ xf.applyAlignment = true
230
244
  end
231
-
245
+
232
246
  if applyProtection
233
247
  xf.protection = CellProtection.new(options)
234
248
  end
235
-
249
+
236
250
  cellXfs << xf
237
251
  end
238
-
239
- # Serializes the styles document
252
+
253
+ # Serializes the object
254
+ # @param [String] str
240
255
  # @return [String]
241
- def to_xml()
242
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
243
- xml.styleSheet(:xmlns => XML_NS) {
244
- [:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
245
- self.instance_values[key.to_s].to_xml(xml) unless self.instance_values[key.to_s].nil?
246
- end
247
- }
256
+ def to_xml_string(str = '')
257
+ str << '<styleSheet xmlns="' << XML_NS << '">'
258
+ [:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
259
+ self.instance_values[key.to_s].to_xml_string(str) unless self.instance_values[key.to_s].nil?
248
260
  end
249
- builder.to_xml(:save_with => 0)
261
+ str << '</styleSheet>'
250
262
  end
251
263
 
252
264
  private
253
- # Creates the default set of styles the exel requires to be valid as well as setting up the
265
+ # Creates the default set of styles the exel requires to be valid as well as setting up the
254
266
  # Axlsx::STYLE_THIN_BORDER
255
267
  def load_default_styles
256
- @numFmts = SimpleTypedList.new NumFmt
268
+ @numFmts = SimpleTypedList.new NumFmt, 'numFmts'
257
269
  @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDD, :formatCode=> "yyyy/mm/dd")
258
270
  @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDDHHMMSS, :formatCode=> "yyyy/mm/dd hh:mm:ss")
259
271
 
260
272
  @numFmts.lock
261
273
 
262
- @fonts = SimpleTypedList.new Font
274
+ @fonts = SimpleTypedList.new Font, 'fonts'
263
275
  @fonts << Font.new(:name => "Arial", :sz => 11, :family=>1)
264
276
  @fonts.lock
265
277
 
266
- @fills = SimpleTypedList.new Fill
278
+ @fills = SimpleTypedList.new Fill, 'fills'
267
279
  @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:none))
268
280
  @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:gray125))
269
281
  @fills.lock
270
282
 
271
- @borders = SimpleTypedList.new Border
283
+ @borders = SimpleTypedList.new Border, 'borders'
272
284
  @borders << Border.new
273
285
  black_border = Border.new
274
- [:left, :right, :top, :bottom].each do |item|
275
- black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000"))
286
+ [:left, :right, :top, :bottom].each do |item|
287
+ black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000"))
276
288
  end
277
289
  @borders << black_border
278
290
  @borders.lock
@@ -281,7 +293,7 @@ module Axlsx
281
293
  @cellStyleXfs << Xf.new(:borderId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
282
294
  @cellStyleXfs.lock
283
295
 
284
- @cellStyles = SimpleTypedList.new CellStyle
296
+ @cellStyles = SimpleTypedList.new CellStyle, 'cellStyles'
285
297
  @cellStyles << CellStyle.new(:name =>"Normal", :builtinId =>0, :xfId=>0)
286
298
  @cellStyles.lock
287
299
 
@@ -297,4 +309,4 @@ module Axlsx
297
309
  end
298
310
  end
299
311
  end
300
-
312
+
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # A single table style definition and is a collection for tableStyleElements
3
4
  # @note Table are not supported in this version and only the defaults required for a valid workbook are created.
@@ -35,13 +36,18 @@ module Axlsx
35
36
  # @see table
36
37
  def table=(v) Axlsx::validate_boolean v; @table=v end
37
38
 
38
- # Serializes the table style
39
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
39
+ # Serializes the object
40
+ # @param [String] str
40
41
  # @return [String]
41
- def to_xml(xml)
42
+ def to_xml_string(str = '')
42
43
  attr = self.instance_values.select { |k, v| [:name, :pivot, :table].include? k }
43
44
  attr[:count] = self.size
44
- xml.tableStyle(attr) { self.each { |table_style_el| table_style_el.to_xml(xml) } }
45
+ str << '<tableStyle '
46
+ str << attr.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
47
+ str << '>'
48
+ each { |table_style_el| table_style_el.to_xml_string(str) }
49
+ str << '</tableStyle>'
45
50
  end
51
+
46
52
  end
47
53
  end
@@ -1,6 +1,7 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
- # an element of style that belongs to a table style.
3
- # @note tables and table styles are not supported in this version. This class exists in preparation for that support.
3
+ # an element of style that belongs to a table style.
4
+ # @note tables and table styles are not supported in this version. This class exists in preparation for that support.
4
5
  class TableStyleElement
5
6
  # The type of style element. The following type are allowed
6
7
  # :wholeTable
@@ -38,7 +39,7 @@ module Axlsx
38
39
  # @return [Integer]
39
40
  attr_reader :size
40
41
 
41
- # The dxfId this style element points to
42
+ # The dxfId this style element points to
42
43
  # @return [Integer]
43
44
  attr_reader :dxfId
44
45
 
@@ -61,11 +62,14 @@ module Axlsx
61
62
  # @see dxfId
62
63
  def dxfId=(v) Axlsx::validate_unsigned_int v; @dxfId = v end
63
64
 
64
- # Serializes the table style element
65
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
65
+ # Serializes the object
66
+ # @param [String] str
66
67
  # @return [String]
67
- def to_xml(xml)
68
- xml.tableStyleElement self.instance_values
68
+ def to_xml_string(str = '')
69
+ str << '<tableStyleElement '
70
+ str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
71
+ str << '/>'
69
72
  end
73
+
70
74
  end
71
75
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # TableStyles represents a collection of style definitions for table styles and pivot table styles.
3
4
  # @note Support for custom table styles does not exist in this version. Many of the classes required are defined in preparation for future release. Please do not attempt to add custom table styles.
@@ -10,13 +11,13 @@ module Axlsx
10
11
  # The default pivot table style. The default value is 'PivotStyleLight6'
11
12
  # @return [String]
12
13
  attr_reader :defaultPivotStyle
13
-
14
+
14
15
  # Creates a new TableStyles object that is a container for TableStyle objects
15
16
  # @option options [String] defaultTableStyle
16
17
  # @option options [String] defaultPivotStyle
17
18
  def initialize(options={})
18
19
  @defaultTableStyle = options[:defaultTableStyle] || "TableStyleMedium9"
19
- @defaultPivotStyle = options[:defaultPivotStyle] || "PivotStyleLight16"
20
+ @defaultPivotStyle = options[:defaultPivotStyle] || "PivotStyleLight16"
20
21
  super TableStyle
21
22
  end
22
23
  # @see defaultTableStyle
@@ -24,16 +25,19 @@ module Axlsx
24
25
  # @see defaultPivotStyle
25
26
  def defaultPivotStyle=(v) Axlsx::validate_string(v); @defaultPivotStyle = v; end
26
27
 
27
- # Serializes the table styles element
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
+ def to_xml_string(str = '')
31
32
  attr = self.instance_values.reject {|k, v| ![:defaultTableStyle, :defaultPivotStyle].include?(k.to_sym) }
32
33
  attr[:count] = self.size
33
- xml.tableStyles(attr) {
34
- self.each { |table_style| table_style.to_xml(xml) }
35
- }
34
+ str << '<tableStyles '
35
+ str << attr.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
36
+ str << '>'
37
+ each { |table_style| table_style.to_xml_string(str) }
38
+ str << '</tableStyles>'
36
39
  end
40
+
37
41
  end
38
42
 
39
43
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # The Xf class defines a formatting record for use in Styles. The recommended way to manage styles for your workbook is with Styles#add_style
3
4
  # @see Styles#add_style
@@ -21,7 +22,7 @@ module Axlsx
21
22
  # index (0 based) of the font to be used in this style
22
23
  # @return [Integer]
23
24
  attr_reader :fontId
24
-
25
+
25
26
  # index (0 based) of the fill to be used in this style
26
27
  # @return [Integer]
27
28
  attr_reader :fillId
@@ -49,7 +50,7 @@ module Axlsx
49
50
  # indicates if the fontId should be applied
50
51
  # @return [Boolean]
51
52
  attr_reader :applyFont
52
-
53
+
53
54
  # indicates if the fillId should be applied
54
55
  # @return [Boolean]
55
56
  attr_reader :applyFill
@@ -74,7 +75,7 @@ module Axlsx
74
75
  # @option options [Integer] xfId
75
76
  # @option options [Boolean] quotePrefix
76
77
  # @option options [Boolean] pivotButton
77
- # @option options [Boolean] applyNumberFormat
78
+ # @option options [Boolean] applyNumberFormat
78
79
  # @option options [Boolean] applyFont
79
80
  # @option options [Boolean] applyFill
80
81
  # @option options [Boolean] applyBorder
@@ -86,8 +87,8 @@ module Axlsx
86
87
  options.each do |o|
87
88
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
88
89
  end
89
- end
90
-
90
+ end
91
+
91
92
  # @see Xf#alignment
92
93
  def alignment=(v) DataTypeValidator.validate "Xf.alignment", CellAlignment, v; @alignment = v end
93
94
 
@@ -95,44 +96,48 @@ module Axlsx
95
96
  def protection=(v) DataTypeValidator.validate "Xf.protection", CellProtection, v; @protection = v end
96
97
 
97
98
  # @see numFmtId
98
- def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
99
+ def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
99
100
 
100
101
  # @see fontId
101
- def fontId=(v) Axlsx::validate_unsigned_int v; @fontId = v end
102
+ def fontId=(v) Axlsx::validate_unsigned_int v; @fontId = v end
102
103
  # @see fillId
103
- def fillId=(v) Axlsx::validate_unsigned_int v; @fillId = v end
104
+ def fillId=(v) Axlsx::validate_unsigned_int v; @fillId = v end
104
105
  # @see borderId
105
- def borderId=(v) Axlsx::validate_unsigned_int v; @borderId = v end
106
+ def borderId=(v) Axlsx::validate_unsigned_int v; @borderId = v end
106
107
  # @see xfId
107
- def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
108
+ def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
108
109
  # @see quotePrefix
109
- def quotePrefix=(v) Axlsx::validate_boolean v; @quotePrefix = v end
110
+ def quotePrefix=(v) Axlsx::validate_boolean v; @quotePrefix = v end
110
111
  # @see pivotButton
111
- def pivotButton=(v) Axlsx::validate_boolean v; @pivotButton = v end
112
+ def pivotButton=(v) Axlsx::validate_boolean v; @pivotButton = v end
112
113
  # @see applyNumberFormat
113
- def applyNumberFormat=(v) Axlsx::validate_boolean v; @applyNumberFormat = v end
114
+ def applyNumberFormat=(v) Axlsx::validate_boolean v; @applyNumberFormat = v end
114
115
  # @see applyFont
115
- def applyFont=(v) Axlsx::validate_boolean v; @applyFont = v end
116
+ def applyFont=(v) Axlsx::validate_boolean v; @applyFont = v end
116
117
  # @see applyFill
117
- def applyFill=(v) Axlsx::validate_boolean v; @applyFill = v end
118
+ def applyFill=(v) Axlsx::validate_boolean v; @applyFill = v end
118
119
 
119
120
  # @see applyBorder
120
- def applyBorder=(v) Axlsx::validate_boolean v; @applyBorder = v end
121
+ def applyBorder=(v) Axlsx::validate_boolean v; @applyBorder = v end
121
122
 
122
123
  # @see applyAlignment
123
- def applyAlignment=(v) Axlsx::validate_boolean v; @applyAlignment = v end
124
+ def applyAlignment=(v) Axlsx::validate_boolean v; @applyAlignment = v end
124
125
 
125
126
  # @see applyProtection
126
- def applyProtection=(v) Axlsx::validate_boolean v; @applyProtection = v end
127
+ def applyProtection=(v) Axlsx::validate_boolean v; @applyProtection = v end
127
128
 
128
- # Serializes the xf elemen
129
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
129
+ # Serializes the object
130
+ # @param [String] str
130
131
  # @return [String]
131
- def to_xml(xml)
132
- xml.xf(self.instance_values.reject { |k, v| [:alignment, :protection, :extList, :name].include? k.to_sym}) {
133
- alignment.to_xml(xml) if self.alignment
134
- protection.to_xml(xml) if self.protection
135
- }
132
+ def to_xml_string(str = '')
133
+ str << '<xf '
134
+ h = instance_values.reject { |k, v| [:alignment, :protection, :extList, :name].include? k.to_sym}
135
+ str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
136
+ str << '>'
137
+ alignment.to_xml_string(str) if self.alignment
138
+ protection.to_xml_string(str) if self.protection
139
+ str << '</xf>'
136
140
  end
141
+
137
142
  end
138
143
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
 
3
4
  # The Cfb class is a MS-OFF-CRYPTOGRAPHY specific OLE (MS-CBF) writer implementation. No attempt is made to re-invent the wheel for read/write of compound binary files.
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
 
3
4
  # XML Encoding
@@ -20,7 +21,7 @@ module Axlsx
20
21
 
21
22
  # dc elements (core) namespace
22
23
  CORE_NS_DC = "http://purl.org/dc/elements/1.1/"
23
-
24
+
24
25
  # dcmit (core) namespcace
25
26
  CORE_NS_DCMIT = "http://purl.org/dc/dcmitype/"
26
27
 
@@ -29,10 +30,10 @@ module Axlsx
29
30
 
30
31
  # xml schema namespace
31
32
  CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
32
-
33
+
33
34
  # spreadsheet drawing namespace
34
35
  XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
35
-
36
+
36
37
  # drawing namespace
37
38
  XML_NS_A = "http://schemas.openxmlformats.org/drawingml/2006/main"
38
39
 
@@ -42,13 +43,12 @@ module Axlsx
42
43
  # relationships namespace
43
44
  XML_NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
44
45
 
45
-
46
46
  # relationships name space
47
47
  RELS_R = "http://schemas.openxmlformats.org/package/2006/relationships"
48
48
 
49
49
  # table rels namespace
50
50
  TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
51
-
51
+
52
52
  # workbook rels namespace
53
53
  WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
54
54
 
@@ -64,6 +64,9 @@ module Axlsx
64
64
  # styles rels namespace
65
65
  STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
66
66
 
67
+ # shared strings namespace
68
+ SHARED_STRINGS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
69
+
67
70
  # drawing rels namespace
68
71
  DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
69
72
 
@@ -76,7 +79,7 @@ module Axlsx
76
79
  # image rels namespace
77
80
  HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
78
81
 
79
- # table content type
82
+ # table content type
80
83
  TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
81
84
 
82
85
  # workbook content type
@@ -86,14 +89,14 @@ module Axlsx
86
89
  APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml"
87
90
 
88
91
  # rels content type
89
- RELS_CT = "application/vnd.openxmlformats-package.relationships+xml"
92
+ RELS_CT = "application/vnd.openxmlformats-package.relationships+xml"
90
93
 
91
94
  # styles content type
92
95
  STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
93
96
 
94
97
  # xml content type
95
98
  XML_CT = "application/xml"
96
-
99
+
97
100
  # worksheet content type
98
101
  WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
99
102
 
@@ -123,7 +126,7 @@ module Axlsx
123
126
 
124
127
  # jpeg extension
125
128
  JPEG_EX = "jpeg"
126
-
129
+
127
130
  # gif extension
128
131
  GIF_EX = "gif"
129
132
 
@@ -138,10 +141,13 @@ module Axlsx
138
141
 
139
142
  # styles part
140
143
  STYLES_PN = "styles.xml"
141
-
144
+
145
+ # shared_strings part
146
+ SHARED_STRINGS_PN = "sharedStrings.xml"
147
+
142
148
  # app part
143
149
  APP_PN = "docProps/app.xml"
144
-
150
+
145
151
  # core part
146
152
  CORE_PN = "docProps/core.xml"
147
153
 
@@ -166,6 +172,9 @@ module Axlsx
166
172
  # drawing rels part
167
173
  DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels"
168
174
 
175
+ # drawing part
176
+ TABLE_PN = "tables/table%d.xml"
177
+
169
178
  # chart part
170
179
  CHART_PN = "charts/chart%d.xml"
171
180
 
@@ -189,12 +198,12 @@ module Axlsx
189
198
 
190
199
  # spreadsheetML validation schema
191
200
  SML_XSD = SCHEMA_BASE + "sml.xsd"
192
-
201
+
193
202
  # drawing validation schema
194
203
  DRAWING_XSD = SCHEMA_BASE + "dml-spreadsheetDrawing.xsd"
195
204
 
196
205
  # number format id for pecentage formatting using the default formatting id.
197
- NUM_FMT_PERCENT = 9
206
+ NUM_FMT_PERCENT = 9
198
207
 
199
208
  # number format id for date format like 2011/11/13
200
209
  NUM_FMT_YYYYMMDD = 100
@@ -209,7 +218,7 @@ module Axlsx
209
218
  STYLE_DATE = 2
210
219
 
211
220
  # error messages RestrictionValidor
212
- ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."
221
+ ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."
213
222
 
214
223
  # error message DataTypeValidator
215
224
  ERR_TYPE = "Invalid Data %s for %s. must be %s."
@@ -217,6 +226,10 @@ module Axlsx
217
226
  # error message for RegexValidator
218
227
  ERR_REGEX = "Invalid Data. %s does not match %s."
219
228
 
229
+ # error message for sheets that use a name which is longer than 31 bytes
230
+ ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be 31 characters (bytes) or less"
231
+
220
232
  # error message for duplicate sheet names
221
233
  ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
234
+
222
235
  end
@@ -1,4 +1,4 @@
1
- # -*- coding: utf-8 -*-
1
+ # encoding: UTF-8
2
2
  require 'digest'
3
3
  require 'base64'
4
4
  require 'openssl'
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Axlsx
2
3
  # The Parser module mixes in a number of methods to help in generating a model from xml
3
4
  # This module is not included in the axlsx library at this time. It is for future development only,