caxlsx 3.3.0 → 4.0.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 (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +25 -7
  4. data/Rakefile +7 -6
  5. data/lib/axlsx/content_type/abstract_content_type.rb +11 -9
  6. data/lib/axlsx/content_type/content_type.rb +7 -9
  7. data/lib/axlsx/content_type/default.rb +4 -6
  8. data/lib/axlsx/content_type/override.rb +3 -5
  9. data/lib/axlsx/doc_props/app.rb +27 -30
  10. data/lib/axlsx/doc_props/core.rb +9 -12
  11. data/lib/axlsx/drawing/area_chart.rb +13 -14
  12. data/lib/axlsx/drawing/area_series.rb +13 -14
  13. data/lib/axlsx/drawing/ax_data_source.rb +3 -6
  14. data/lib/axlsx/drawing/axes.rb +10 -9
  15. data/lib/axlsx/drawing/axis.rb +27 -30
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +17 -18
  17. data/lib/axlsx/drawing/bar_chart.rb +16 -17
  18. data/lib/axlsx/drawing/bar_series.rb +9 -13
  19. data/lib/axlsx/drawing/bubble_chart.rb +8 -9
  20. data/lib/axlsx/drawing/bubble_series.rb +9 -10
  21. data/lib/axlsx/drawing/cat_axis.rb +14 -17
  22. data/lib/axlsx/drawing/chart.rb +25 -28
  23. data/lib/axlsx/drawing/d_lbls.rb +29 -26
  24. data/lib/axlsx/drawing/drawing.rb +60 -62
  25. data/lib/axlsx/drawing/graphic_frame.rb +6 -7
  26. data/lib/axlsx/drawing/hyperlink.rb +12 -13
  27. data/lib/axlsx/drawing/line_3D_chart.rb +13 -15
  28. data/lib/axlsx/drawing/line_chart.rb +13 -14
  29. data/lib/axlsx/drawing/line_series.rb +13 -14
  30. data/lib/axlsx/drawing/marker.rb +14 -16
  31. data/lib/axlsx/drawing/num_data.rb +13 -16
  32. data/lib/axlsx/drawing/num_data_source.rb +11 -13
  33. data/lib/axlsx/drawing/num_val.rb +9 -10
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +10 -10
  35. data/lib/axlsx/drawing/pic.rb +57 -22
  36. data/lib/axlsx/drawing/picture_locking.rb +6 -7
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +6 -9
  38. data/lib/axlsx/drawing/pie_series.rb +9 -12
  39. data/lib/axlsx/drawing/scaling.rb +9 -10
  40. data/lib/axlsx/drawing/scatter_chart.rb +9 -10
  41. data/lib/axlsx/drawing/scatter_series.rb +15 -16
  42. data/lib/axlsx/drawing/ser_axis.rb +9 -11
  43. data/lib/axlsx/drawing/series.rb +8 -8
  44. data/lib/axlsx/drawing/series_title.rb +6 -6
  45. data/lib/axlsx/drawing/str_data.rb +10 -13
  46. data/lib/axlsx/drawing/str_val.rb +8 -9
  47. data/lib/axlsx/drawing/title.rb +23 -27
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +8 -8
  49. data/lib/axlsx/drawing/val_axis.rb +5 -6
  50. data/lib/axlsx/drawing/view_3D.rb +32 -30
  51. data/lib/axlsx/drawing/vml_drawing.rb +19 -20
  52. data/lib/axlsx/drawing/vml_shape.rb +25 -26
  53. data/lib/axlsx/package.rb +81 -79
  54. data/lib/axlsx/rels/relationship.rb +30 -28
  55. data/lib/axlsx/rels/relationships.rb +7 -8
  56. data/lib/axlsx/stylesheet/border.rb +7 -8
  57. data/lib/axlsx/stylesheet/border_pr.rb +8 -8
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +14 -20
  59. data/lib/axlsx/stylesheet/cell_protection.rb +6 -7
  60. data/lib/axlsx/stylesheet/cell_style.rb +12 -14
  61. data/lib/axlsx/stylesheet/color.rb +15 -12
  62. data/lib/axlsx/stylesheet/dxf.rb +7 -9
  63. data/lib/axlsx/stylesheet/fill.rb +3 -5
  64. data/lib/axlsx/stylesheet/font.rb +24 -21
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +9 -9
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +7 -6
  67. data/lib/axlsx/stylesheet/num_fmt.rb +9 -14
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +8 -8
  69. data/lib/axlsx/stylesheet/styles.rb +104 -98
  70. data/lib/axlsx/stylesheet/table_style.rb +8 -9
  71. data/lib/axlsx/stylesheet/table_style_element.rb +7 -8
  72. data/lib/axlsx/stylesheet/table_styles.rb +8 -10
  73. data/lib/axlsx/stylesheet/xf.rb +21 -22
  74. data/lib/axlsx/util/accessors.rb +6 -6
  75. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  76. data/lib/axlsx/util/constants.rb +119 -108
  77. data/lib/axlsx/util/mime_type_utils.rb +11 -0
  78. data/lib/axlsx/util/options_parser.rb +4 -3
  79. data/lib/axlsx/util/serialized_attributes.rb +45 -21
  80. data/lib/axlsx/util/simple_typed_list.rb +58 -57
  81. data/lib/axlsx/util/storage.rb +38 -41
  82. data/lib/axlsx/util/validators.rb +107 -44
  83. data/lib/axlsx/util/zip_command.rb +10 -12
  84. data/lib/axlsx/version.rb +3 -2
  85. data/lib/axlsx/workbook/defined_name.rb +11 -8
  86. data/lib/axlsx/workbook/defined_names.rb +4 -3
  87. data/lib/axlsx/workbook/shared_strings_table.rb +10 -11
  88. data/lib/axlsx/workbook/workbook.rb +121 -114
  89. data/lib/axlsx/workbook/workbook_view.rb +8 -11
  90. data/lib/axlsx/workbook/workbook_views.rb +4 -4
  91. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +72 -14
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -7
  93. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +24 -21
  94. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  95. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
  96. data/lib/axlsx/workbook/worksheet/border_creator.rb +30 -25
  97. data/lib/axlsx/workbook/worksheet/break.rb +4 -5
  98. data/lib/axlsx/workbook/worksheet/cell.rb +92 -65
  99. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +32 -28
  100. data/lib/axlsx/workbook/worksheet/cfvo.rb +7 -5
  101. data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
  102. data/lib/axlsx/workbook/worksheet/col.rb +9 -10
  103. data/lib/axlsx/workbook/worksheet/col_breaks.rb +8 -7
  104. data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
  105. data/lib/axlsx/workbook/worksheet/cols.rb +9 -7
  106. data/lib/axlsx/workbook/worksheet/comment.rb +12 -11
  107. data/lib/axlsx/workbook/worksheet/comments.rb +10 -12
  108. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +12 -8
  109. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +19 -21
  110. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +5 -5
  111. data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
  112. data/lib/axlsx/workbook/worksheet/data_validation.rb +34 -33
  113. data/lib/axlsx/workbook/worksheet/data_validations.rb +5 -6
  114. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
  115. data/lib/axlsx/workbook/worksheet/dimension.rb +9 -6
  116. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -3
  117. data/lib/axlsx/workbook/worksheet/icon_set.rb +24 -8
  118. data/lib/axlsx/workbook/worksheet/merged_cells.rb +10 -10
  119. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -3
  120. data/lib/axlsx/workbook/worksheet/page_margins.rb +17 -12
  121. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -4
  122. data/lib/axlsx/workbook/worksheet/page_setup.rb +128 -129
  123. data/lib/axlsx/workbook/worksheet/pane.rb +27 -26
  124. data/lib/axlsx/workbook/worksheet/pivot_table.rb +23 -25
  125. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
  126. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +5 -4
  127. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -2
  128. data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
  129. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +12 -10
  130. data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
  131. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +35 -17
  132. data/lib/axlsx/workbook/worksheet/row.rb +30 -22
  133. data/lib/axlsx/workbook/worksheet/row_breaks.rb +8 -7
  134. data/lib/axlsx/workbook/worksheet/selection.rb +16 -16
  135. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +10 -7
  136. data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
  137. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
  138. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +11 -7
  139. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +21 -20
  140. data/lib/axlsx/workbook/worksheet/sheet_view.rb +48 -53
  141. data/lib/axlsx/workbook/worksheet/table.rb +13 -13
  142. data/lib/axlsx/workbook/worksheet/table_style_info.rb +6 -5
  143. data/lib/axlsx/workbook/worksheet/tables.rb +7 -5
  144. data/lib/axlsx/workbook/worksheet/worksheet.rb +92 -63
  145. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +10 -8
  146. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
  147. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +9 -8
  148. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +7 -5
  149. data/lib/axlsx.rb +75 -47
  150. data/lib/caxlsx.rb +3 -2
  151. metadata +50 -44
@@ -1,24 +1,25 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
- require 'axlsx/stylesheet/border.rb'
4
- require 'axlsx/stylesheet/border_pr.rb'
5
- require 'axlsx/stylesheet/cell_alignment.rb'
6
- require 'axlsx/stylesheet/cell_style.rb'
7
- require 'axlsx/stylesheet/color.rb'
8
- require 'axlsx/stylesheet/fill.rb'
9
- require 'axlsx/stylesheet/font.rb'
10
- require 'axlsx/stylesheet/gradient_fill.rb'
11
- require 'axlsx/stylesheet/gradient_stop.rb'
12
- require 'axlsx/stylesheet/num_fmt.rb'
13
- require 'axlsx/stylesheet/pattern_fill.rb'
14
- require 'axlsx/stylesheet/table_style.rb'
15
- require 'axlsx/stylesheet/table_styles.rb'
16
- require 'axlsx/stylesheet/table_style_element.rb'
17
- require 'axlsx/stylesheet/dxf.rb'
18
- require 'axlsx/stylesheet/xf.rb'
19
- require 'axlsx/stylesheet/cell_protection.rb'
20
-
21
- #The Styles class manages worksheet styles
4
+ require 'axlsx/stylesheet/border'
5
+ require 'axlsx/stylesheet/border_pr'
6
+ require 'axlsx/stylesheet/cell_alignment'
7
+ require 'axlsx/stylesheet/cell_style'
8
+ require 'axlsx/stylesheet/color'
9
+ require 'axlsx/stylesheet/fill'
10
+ require 'axlsx/stylesheet/font'
11
+ require 'axlsx/stylesheet/gradient_fill'
12
+ require 'axlsx/stylesheet/gradient_stop'
13
+ require 'axlsx/stylesheet/num_fmt'
14
+ require 'axlsx/stylesheet/pattern_fill'
15
+ require 'axlsx/stylesheet/table_style'
16
+ require 'axlsx/stylesheet/table_styles'
17
+ require 'axlsx/stylesheet/table_style_element'
18
+ require 'axlsx/stylesheet/dxf'
19
+ require 'axlsx/stylesheet/xf'
20
+ require 'axlsx/stylesheet/cell_protection'
21
+
22
+ # The Styles class manages worksheet styles
22
23
  # In addition to creating the require style objects for a valid xlsx package, this class provides the key mechanism for adding styles to your workbook, and safely applying them to the cells of your worksheet.
23
24
  # All portions of the stylesheet are implemented here exception colors, which specify legacy and modified pallete colors, and exLst, whic is used as a future feature data storage area.
24
25
  # @see Office Open XML Part 1 18.8.11 for gory details on how this stuff gets put together
@@ -109,14 +110,14 @@ module Axlsx
109
110
  # @see Styles#add_style
110
111
  attr_reader :dxfs
111
112
 
112
- # The collection of table styles that will be available to the user in the excel UI
113
+ # The collection of table styles that will be available to the user in the Excel UI
113
114
  # @return [SimpleTypedList]
114
115
  # @note The recommended way to manage styles is with add_style
115
116
  # @see Styles#add_style
116
117
  attr_reader :tableStyles
117
118
 
118
119
  # Creates a new Styles object and prepopulates it with the requires objects to generate a valid package style part.
119
- def initialize()
120
+ def initialize
120
121
  load_default_styles
121
122
  end
122
123
 
@@ -137,7 +138,7 @@ module Axlsx
137
138
  # @option options [Integer] family The font family to use.
138
139
  # @option options [String] font_name The name of the font to use
139
140
  # @option options [Integer] num_fmt The number format to apply
140
- # @option options [String] format_code The formatting to apply.
141
+ # @option options [String] format_code The formatting to apply.
141
142
  # @option options [Integer|Hash] border The border style to use.
142
143
  # borders support style, color and edges options @see parse_border_options
143
144
  # @option options [String] bg_color The background color to apply to the cell
@@ -225,22 +226,26 @@ module Axlsx
225
226
  #
226
227
  # An index for cell styles where keys are styles codes as per Axlsx::Style and values are Cell#raw_style
227
228
  # The reason for the backward key/value ordering is that style lookup must be most efficient, while `add_style` can be less efficient
228
- def add_style(options={})
229
+ def add_style(options = {})
229
230
  # Default to :xf
230
231
  options[:type] ||= :xf
231
232
 
232
- raise ArgumentError, "Type must be one of [:xf, :dxf]" unless [:xf, :dxf].include?(options[:type] )
233
+ raise ArgumentError, "Type must be one of [:xf, :dxf]" unless [:xf, :dxf].include?(options[:type])
233
234
 
234
- if options[:border].is_a?(Hash) && options[:border][:edges] == :all
235
- options[:border][:edges] = Axlsx::Border::EDGES
235
+ if options[:border].is_a?(Hash)
236
+ if options[:border][:edges] == :all
237
+ options[:border][:edges] = Axlsx::Border::EDGES
238
+ elsif options[:border][:edges]
239
+ options[:border][:edges] = options[:border][:edges].map(&:to_sym) ### normalize for style caching
240
+ end
236
241
  end
237
242
 
238
243
  if options[:type] == :xf
239
244
  # Check to see if style in cache already
240
-
241
- font_defaults = {name: @fonts.first.name, sz: @fonts.first.sz, family: @fonts.first.family}
242
245
 
243
- raw_style = {type: :xf}.merge(font_defaults).merge(options)
246
+ font_defaults = { name: @fonts.first.name, sz: @fonts.first.sz, family: @fonts.first.family }
247
+
248
+ raw_style = { type: :xf }.merge(font_defaults).merge(options)
244
249
 
245
250
  if raw_style[:format_code]
246
251
  raw_style.delete(:num_fmt)
@@ -260,12 +265,12 @@ module Axlsx
260
265
  alignment = parse_alignment_options options
261
266
  protection = parse_protection_options options
262
267
 
263
- case options[:type]
264
- when :dxf
265
- style = Dxf.new :fill => fill, :font => font, :numFmt => numFmt, :border => border, :alignment => alignment, :protection => protection
266
- else
267
- style = Xf.new :fillId=>fill || 0, :fontId=>font || 0, :numFmtId=>numFmt || 0, :borderId=>border || 0, :alignment => alignment, :protection => protection, :applyFill=>!fill.nil?, :applyFont=>!font.nil?, :applyNumberFormat =>!numFmt.nil?, :applyBorder=>!border.nil?, :applyAlignment => !alignment.nil?, :applyProtection => !protection.nil?
268
- end
268
+ style = case options[:type]
269
+ when :dxf
270
+ Dxf.new fill: fill, font: font, numFmt: numFmt, border: border, alignment: alignment, protection: protection
271
+ else
272
+ Xf.new fillId: fill || 0, fontId: font || 0, numFmtId: numFmt || 0, borderId: border || 0, alignment: alignment, protection: protection, applyFill: !fill.nil?, applyFont: !font.nil?, applyNumberFormat: !numFmt.nil?, applyBorder: !border.nil?, applyAlignment: !alignment.nil?, applyProtection: !protection.nil?
273
+ end
269
274
 
270
275
  if options[:type] == :xf
271
276
  xf_index = (cellXfs << style)
@@ -273,11 +278,9 @@ module Axlsx
273
278
  # Add styles to style_index cache for re-use
274
279
  style_index[xf_index] = raw_style
275
280
 
276
- return xf_index
281
+ xf_index
277
282
  else
278
- dxf_index = (dxfs << style)
279
-
280
- return dxf_index
283
+ dxfs << style
281
284
  end
282
285
  end
283
286
 
@@ -287,8 +290,9 @@ module Axlsx
287
290
  # @option options [Boolean] hide boolean value defining cell protection attribute for hiding.
288
291
  # @option options [Boolean] locked boolean value defining cell protection attribute for locking.
289
292
  # @return [CellProtection]
290
- def parse_protection_options(options={})
293
+ def parse_protection_options(options = {})
291
294
  return if (options.keys & [:hidden, :locked]).empty?
295
+
292
296
  CellProtection.new(options)
293
297
  end
294
298
 
@@ -297,8 +301,9 @@ module Axlsx
297
301
  # @option options [Hash] alignment A hash of options to prive the CellAlignment intializer
298
302
  # @return [CellAlignment]
299
303
  # @see CellAlignment
300
- def parse_alignment_options(options={})
304
+ def parse_alignment_options(options = {})
301
305
  return unless options[:alignment]
306
+
302
307
  CellAlignment.new options[:alignment]
303
308
  end
304
309
 
@@ -317,14 +322,15 @@ module Axlsx
317
322
  # @option options [Integer] family The font family to use.
318
323
  # @option options [String] font_name The name of the font to use
319
324
  # @return [Font|Integer]
320
- def parse_font_options(options={})
325
+ def parse_font_options(options = {})
321
326
  return if (options.keys & [:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name]).empty?
327
+
322
328
  Axlsx.instance_values_for(fonts.first).each do |key, value|
323
329
  # Thanks for that 1.8.7 - cant do a simple merge...
324
- options[key.to_sym] = value unless options.keys.include?(key.to_sym)
330
+ options[key.to_sym] = value unless options.key?(key.to_sym)
325
331
  end
326
332
  font = Font.new(options)
327
- font.color = Color.new(:rgb => options[:fg_color]) if options[:fg_color]
333
+ font.color = Color.new(rgb: options[:fg_color]) if options[:fg_color]
328
334
  font.name = options[:font_name] if options[:font_name]
329
335
  options[:type] == :dxf ? font : fonts << font
330
336
  end
@@ -333,37 +339,38 @@ module Axlsx
333
339
  # @note noop if :bg_color is not specified in options
334
340
  # @option options [String] bg_color The rgb color to apply to the fill
335
341
  # @return [Fill|Integer]
336
- def parse_fill_options(options={})
342
+ def parse_fill_options(options = {})
337
343
  return unless options[:bg_color]
338
- color = Color.new(:rgb=>options[:bg_color])
344
+
345
+ color = Color.new(rgb: options[:bg_color])
339
346
  dxf = options[:type] == :dxf
340
347
  color_key = dxf ? :bgColor : :fgColor
341
- pattern = PatternFill.new(:patternType =>:solid, color_key=>color)
348
+ pattern = PatternFill.new(:patternType => :solid, color_key => color)
342
349
  fill = Fill.new(pattern)
343
350
  dxf ? fill : fills << fill
344
351
  end
345
352
 
346
353
  # parses Style#add_style options for borders.
347
354
  # @note noop if :border is not specified in options
348
- # @option options [Hash|Integer] A border style definition hash or the index of an existing border.
349
- # Border style definition hashes must include :style and :color key-value entries and
350
- # may include an :edges entry that references an array of symbols identifying which border edges
355
+ # @option options [Hash|Integer] A border style definition hash or the index of an existing border.
356
+ # Border style definition hashes must include :style and :color key-value entries and
357
+ # may include an :edges entry that references an array of symbols identifying which border edges
351
358
  # you wish to apply the style or any other valid Border initializer options.
352
359
  # If the :edges entity is not provided the style is applied to all edges of cells that reference this style.
353
- # Also available :border_top, :border_right, :border_bottom and :border_left options with :style and/or :color
360
+ # Also available :border_top, :border_right, :border_bottom and :border_left options with :style and/or :color
354
361
  # key-value entries, which override :border values.
355
362
  # @example
356
363
  # #apply a thick red border to the top and bottom
357
364
  # { :border => { :style => :thick, :color => "FFFF0000", :edges => [:top, :bottom] }
358
365
  # @return [Border|Integer]
359
- def parse_border_options(options={})
360
- if options[:border].nil? && Border::EDGES.all?{|x| options["border_#{x}".to_sym].nil? }
366
+ def parse_border_options(options = {})
367
+ if options[:border].nil? && Border::EDGES.all? { |x| options["border_#{x}".to_sym].nil? }
361
368
  return nil
362
369
  end
363
370
 
364
371
  if options[:border].is_a?(Integer)
365
372
  if options[:border] >= borders.size
366
- raise ArgumentError, (ERR_INVALID_BORDER_ID % options[:border])
373
+ raise ArgumentError, format(ERR_INVALID_BORDER_ID, options[:border])
367
374
  end
368
375
 
369
376
  if options[:type] == :dxf
@@ -373,9 +380,9 @@ module Axlsx
373
380
  end
374
381
  end
375
382
 
376
- validate_border_hash = ->(val){
377
- if !(val.keys.include?(:style) && val.keys.include?(:color))
378
- raise ArgumentError, (ERR_INVALID_BORDER_OPTIONS % options[:border])
383
+ validate_border_hash = lambda { |val|
384
+ unless val.key?(:style) && val.key?(:color)
385
+ raise ArgumentError, format(ERR_INVALID_BORDER_OPTIONS, options[:border])
379
386
  end
380
387
  }
381
388
 
@@ -383,24 +390,22 @@ module Axlsx
383
390
 
384
391
  if options[:border].nil?
385
392
  base_border_opts = {}
386
- else
387
- if options[:border].is_a?(Array)
388
- borders_array += options[:border]
393
+ elsif options[:border].is_a?(Array)
394
+ borders_array += options[:border]
389
395
 
390
- base_border_opts = {}
396
+ base_border_opts = {}
391
397
 
392
- options[:border].each do |b_opts|
393
- if b_opts[:edges].nil?
394
- base_border_opts = base_border_opts.merge(b_opts)
395
- end
398
+ options[:border].each do |b_opts|
399
+ if b_opts[:edges].nil?
400
+ base_border_opts = base_border_opts.merge(b_opts)
396
401
  end
397
- else
398
- borders_array << options[:border]
402
+ end
403
+ else
404
+ borders_array << options[:border]
399
405
 
400
- base_border_opts = options[:border]
406
+ base_border_opts = options[:border]
401
407
 
402
- validate_border_hash.call(base_border_opts)
403
- end
408
+ validate_border_hash.call(base_border_opts)
404
409
  end
405
410
 
406
411
  Border::EDGES.each do |edge|
@@ -434,23 +439,23 @@ module Axlsx
434
439
  next
435
440
  end
436
441
 
437
- if !edge_b_opts.empty?
442
+ unless edge_b_opts.empty?
438
443
  if base_border_opts.empty?
439
444
  validate_border_hash.call(edge_b_opts)
440
445
  end
441
446
 
442
447
  border.prs << BorderPr.new({
443
- :name => edge,
444
- :style => edge_b_opts[:style],
445
- :color => Color.new(:rgb => edge_b_opts[:color]) },
446
- )
448
+ name: edge,
449
+ style: edge_b_opts[:style],
450
+ color: Color.new(rgb: edge_b_opts[:color])
451
+ })
447
452
  end
448
453
  end
449
454
 
450
455
  if options[:type] == :dxf
451
- return border
456
+ border
452
457
  else
453
- return borders << border
458
+ borders << border
454
459
  end
455
460
  end
456
461
 
@@ -458,15 +463,15 @@ module Axlsx
458
463
  # noop if neither :format_code or :num_format options are set.
459
464
  # @option options [Hash] A hash describing the :format_code and/or :num_fmt integer for the style.
460
465
  # @return [NumFmt|Integer]
461
- def parse_num_fmt_options(options={})
466
+ def parse_num_fmt_options(options = {})
462
467
  return if (options.keys & [:format_code, :num_fmt]).empty?
463
468
 
464
- #When the user provides format_code - we always need to create a new numFmt object
465
- #When the type is :dxf we always need to create a new numFmt object
469
+ # When the user provides format_code - we always need to create a new numFmt object
470
+ # When the type is :dxf we always need to create a new numFmt object
466
471
  if options[:format_code] || options[:type] == :dxf
467
- #If this is a standard xf we pull from numFmts the highest current and increment for num_fmt
468
- options[:num_fmt] ||= (@numFmts.map{ |num_fmt| num_fmt.numFmtId }.max + 1) if options[:type] != :dxf
469
- numFmt = NumFmt.new(:numFmtId => options[:num_fmt] || 0, :formatCode=> options[:format_code].to_s)
472
+ # If this is a standard xf we pull from numFmts the highest current and increment for num_fmt
473
+ options[:num_fmt] ||= (@numFmts.map(&:numFmtId).max + 1) if options[:type] != :dxf
474
+ numFmt = NumFmt.new(numFmtId: options[:num_fmt] || 0, formatCode: options[:format_code].to_s)
470
475
  options[:type] == :dxf ? numFmt : (numFmts << numFmt; numFmt.numFmtId)
471
476
  else
472
477
  options[:num_fmt]
@@ -476,8 +481,8 @@ module Axlsx
476
481
  # Serializes the object
477
482
  # @param [String] str
478
483
  # @return [String]
479
- def to_xml_string(str = '')
480
- str << ('<styleSheet xmlns="' << XML_NS << '">')
484
+ def to_xml_string(str = +'')
485
+ str << '<styleSheet xmlns="' << XML_NS << '">'
481
486
  instance_vals = Axlsx.instance_values_for(self)
482
487
  [:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
483
488
  instance_vals[key.to_s].to_xml_string(str) unless instance_vals[key.to_s].nil?
@@ -486,50 +491,51 @@ module Axlsx
486
491
  end
487
492
 
488
493
  private
494
+
489
495
  # Creates the default set of styles the exel requires to be valid as well as setting up the
490
496
  # Axlsx::STYLE_THIN_BORDER
491
497
  def load_default_styles
492
498
  @numFmts = SimpleTypedList.new NumFmt, 'numFmts'
493
- @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDD, :formatCode=> "yyyy/mm/dd")
494
- @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDDHHMMSS, :formatCode=> "yyyy/mm/dd hh:mm:ss")
499
+ @numFmts << NumFmt.new(numFmtId: NUM_FMT_YYYYMMDD, formatCode: "yyyy/mm/dd")
500
+ @numFmts << NumFmt.new(numFmtId: NUM_FMT_YYYYMMDDHHMMSS, formatCode: "yyyy/mm/dd hh:mm:ss")
495
501
 
496
502
  @numFmts.lock
497
503
 
498
504
  @fonts = SimpleTypedList.new Font, 'fonts'
499
- @fonts << Font.new(:name => "Arial", :sz => 11, :family=>1)
505
+ @fonts << Font.new(name: "Arial", sz: 11, family: 1)
500
506
  @fonts.lock
501
507
 
502
508
  @fills = SimpleTypedList.new Fill, 'fills'
503
- @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:none))
504
- @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:gray125))
509
+ @fills << Fill.new(Axlsx::PatternFill.new(patternType: :none))
510
+ @fills << Fill.new(Axlsx::PatternFill.new(patternType: :gray125))
505
511
  @fills.lock
506
512
 
507
513
  @borders = SimpleTypedList.new Border, 'borders'
508
514
  @borders << Border.new
509
515
  black_border = Border.new
510
516
  [:left, :right, :top, :bottom].each do |item|
511
- black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000"))
517
+ black_border.prs << BorderPr.new(name: item, style: :thin, color: Color.new(rgb: "FF000000"))
512
518
  end
513
519
  @borders << black_border
514
520
  @borders.lock
515
521
 
516
522
  @cellStyleXfs = SimpleTypedList.new Xf, "cellStyleXfs"
517
- @cellStyleXfs << Xf.new(:borderId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
523
+ @cellStyleXfs << Xf.new(borderId: 0, numFmtId: 0, fontId: 0, fillId: 0)
518
524
  @cellStyleXfs.lock
519
525
 
520
526
  @cellStyles = SimpleTypedList.new CellStyle, 'cellStyles'
521
- @cellStyles << CellStyle.new(:name =>"Normal", :builtinId =>0, :xfId=>0)
527
+ @cellStyles << CellStyle.new(name: "Normal", builtinId: 0, xfId: 0)
522
528
  @cellStyles.lock
523
529
 
524
530
  @cellXfs = SimpleTypedList.new Xf, "cellXfs"
525
- @cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
526
- @cellXfs << Xf.new(:borderId=>1, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
531
+ @cellXfs << Xf.new(borderId: 0, xfId: 0, numFmtId: 0, fontId: 0, fillId: 0)
532
+ @cellXfs << Xf.new(borderId: 1, xfId: 0, numFmtId: 0, fontId: 0, fillId: 0)
527
533
  # default date formatting
528
- @cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>14, :fontId=>0, :fillId=>0, :applyNumberFormat=>1)
534
+ @cellXfs << Xf.new(borderId: 0, xfId: 0, numFmtId: 14, fontId: 0, fillId: 0, applyNumberFormat: 1)
529
535
  @cellXfs.lock
530
536
 
531
537
  @dxfs = SimpleTypedList.new(Dxf, "dxfs"); @dxfs.lock
532
- @tableStyles = TableStyles.new(:defaultTableStyle => "TableStyleMedium9", :defaultPivotStyle => "PivotStyleLight16"); @tableStyles.lock
538
+ @tableStyles = TableStyles.new(defaultTableStyle: "TableStyleMedium9", defaultPivotStyle: "PivotStyleLight16"); @tableStyles.lock
533
539
  end
534
540
  end
535
541
  end
@@ -1,9 +1,9 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # A single table style definition and is a collection for tableStyleElements
4
5
  # @note Table are not supported in this version and only the defaults required for a valid workbook are created.
5
6
  class TableStyle < SimpleTypedList
6
-
7
7
  include Axlsx::OptionsParser
8
8
  include Axlsx::SerializedAttributes
9
9
 
@@ -12,7 +12,7 @@ module Axlsx
12
12
  # @param [String] name
13
13
  # @option options [Boolean] pivot
14
14
  # @option options [Boolean] table
15
- def initialize(name, options={})
15
+ def initialize(name, options = {})
16
16
  self.name = name
17
17
  parse_options options
18
18
  super TableStyleElement
@@ -33,22 +33,21 @@ module Axlsx
33
33
  attr_reader :table
34
34
 
35
35
  # @see name
36
- def name=(v) Axlsx::validate_string v; @name=v end
36
+ def name=(v) Axlsx.validate_string v; @name = v end
37
37
  # @see pivot
38
- def pivot=(v) Axlsx::validate_boolean v; @pivot=v end
38
+ def pivot=(v) Axlsx.validate_boolean v; @pivot = v end
39
39
  # @see table
40
- def table=(v) Axlsx::validate_boolean v; @table=v end
40
+ def table=(v) Axlsx.validate_boolean v; @table = v end
41
41
 
42
42
  # Serializes the object
43
43
  # @param [String] str
44
44
  # @return [String]
45
- def to_xml_string(str = '')
45
+ def to_xml_string(str = +'')
46
46
  str << '<tableStyle '
47
- serialized_attributes str, {:count => self.size}
47
+ serialized_attributes str, { count: size }
48
48
  str << '>'
49
49
  each { |table_style_el| table_style_el.to_xml_string(str) }
50
50
  str << '</tableStyle>'
51
51
  end
52
-
53
52
  end
54
53
  end
@@ -1,9 +1,9 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # an element of style that belongs to a table style.
4
5
  # @note tables and table styles are not supported in this version. This class exists in preparation for that support.
5
6
  class TableStyleElement
6
-
7
7
  include Axlsx::OptionsParser
8
8
  include Axlsx::SerializedAttributes
9
9
 
@@ -11,7 +11,7 @@ module Axlsx
11
11
  # @option options [Symbol] type
12
12
  # @option options [Integer] size
13
13
  # @option options [Integer] dxfId
14
- def initialize(options={})
14
+ def initialize(options = {})
15
15
  parse_options options
16
16
  end
17
17
 
@@ -58,20 +58,19 @@ module Axlsx
58
58
  attr_reader :dxfId
59
59
 
60
60
  # @see type
61
- def type=(v) Axlsx::validate_table_element_type v; @type = v end
61
+ def type=(v) Axlsx.validate_table_element_type v; @type = v end
62
62
 
63
63
  # @see size
64
- def size=(v) Axlsx::validate_unsigned_int v; @size = v end
64
+ def size=(v) Axlsx.validate_unsigned_int v; @size = v end
65
65
 
66
66
  # @see dxfId
67
- def dxfId=(v) Axlsx::validate_unsigned_int v; @dxfId = v end
67
+ def dxfId=(v) Axlsx.validate_unsigned_int v; @dxfId = v end
68
68
 
69
69
  # Serializes the object
70
70
  # @param [String] str
71
71
  # @return [String]
72
- def to_xml_string(str = '')
72
+ def to_xml_string(str = +'')
73
73
  serialized_tag('tableStyleElement', str)
74
74
  end
75
-
76
75
  end
77
76
  end
@@ -1,15 +1,15 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # TableStyles represents a collection of style definitions for table styles and pivot table styles.
4
5
  # @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.
5
6
  class TableStyles < SimpleTypedList
6
-
7
7
  include Axlsx::SerializedAttributes
8
8
 
9
9
  # Creates a new TableStyles object that is a container for TableStyle objects
10
10
  # @option options [String] defaultTableStyle
11
11
  # @option options [String] defaultPivotStyle
12
- def initialize(options={})
12
+ def initialize(options = {})
13
13
  @defaultTableStyle = options[:defaultTableStyle] || "TableStyleMedium9"
14
14
  @defaultPivotStyle = options[:defaultPivotStyle] || "PivotStyleLight16"
15
15
  super TableStyle
@@ -25,22 +25,20 @@ module Axlsx
25
25
  # @return [String]
26
26
  attr_reader :defaultPivotStyle
27
27
 
28
- # @see defaultTableStyle
29
- def defaultTableStyle=(v) Axlsx::validate_string(v); @defaultTableStyle = v; end
28
+ # @see defaultTableStyle
29
+ def defaultTableStyle=(v) Axlsx.validate_string(v); @defaultTableStyle = v; end
30
30
  # @see defaultPivotStyle
31
- def defaultPivotStyle=(v) Axlsx::validate_string(v); @defaultPivotStyle = v; end
31
+ def defaultPivotStyle=(v) Axlsx.validate_string(v); @defaultPivotStyle = v; end
32
32
 
33
33
  # Serializes the object
34
34
  # @param [String] str
35
35
  # @return [String]
36
- def to_xml_string(str = '')
36
+ def to_xml_string(str = +'')
37
37
  str << '<tableStyles '
38
- serialized_attributes str, {:count => self.size }
38
+ serialized_attributes str, { count: size }
39
39
  str << '>'
40
40
  each { |table_style| table_style.to_xml_string(str) }
41
41
  str << '</tableStyles>'
42
42
  end
43
-
44
43
  end
45
-
46
44
  end
@@ -1,9 +1,10 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # 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
4
5
  # @see Styles#add_style
5
6
  class Xf
6
- #does not support extList (ExtensionList)
7
+ # does not support extList (ExtensionList)
7
8
 
8
9
  include Axlsx::SerializedAttributes
9
10
  include Axlsx::OptionsParser
@@ -23,7 +24,7 @@ module Axlsx
23
24
  # @option options [Boolean] applyProtection
24
25
  # @option options [CellAlignment] alignment
25
26
  # @option options [CellProtection] protection
26
- def initialize(options={})
27
+ def initialize(options = {})
27
28
  parse_options options
28
29
  end
29
30
 
@@ -93,55 +94,53 @@ module Axlsx
93
94
  # @return [Boolean]
94
95
  attr_reader :applyProtection
95
96
 
96
- # @see Xf#alignment
97
+ # @see Xf#alignment
97
98
  def alignment=(v) DataTypeValidator.validate "Xf.alignment", CellAlignment, v; @alignment = v end
98
99
 
99
100
  # @see protection
100
101
  def protection=(v) DataTypeValidator.validate "Xf.protection", CellProtection, v; @protection = v end
101
102
 
102
103
  # @see numFmtId
103
- def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
104
+ def numFmtId=(v) Axlsx.validate_unsigned_int v; @numFmtId = v end
104
105
 
105
106
  # @see fontId
106
- def fontId=(v) Axlsx::validate_unsigned_int v; @fontId = v end
107
+ def fontId=(v) Axlsx.validate_unsigned_int v; @fontId = v end
107
108
  # @see fillId
108
- def fillId=(v) Axlsx::validate_unsigned_int v; @fillId = v end
109
+ def fillId=(v) Axlsx.validate_unsigned_int v; @fillId = v end
109
110
  # @see borderId
110
- def borderId=(v) Axlsx::validate_unsigned_int v; @borderId = v end
111
+ def borderId=(v) Axlsx.validate_unsigned_int v; @borderId = v end
111
112
  # @see xfId
112
- def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
113
+ def xfId=(v) Axlsx.validate_unsigned_int v; @xfId = v end
113
114
  # @see quotePrefix
114
- def quotePrefix=(v) Axlsx::validate_boolean v; @quotePrefix = v end
115
+ def quotePrefix=(v) Axlsx.validate_boolean v; @quotePrefix = v end
115
116
  # @see pivotButton
116
- def pivotButton=(v) Axlsx::validate_boolean v; @pivotButton = v end
117
+ def pivotButton=(v) Axlsx.validate_boolean v; @pivotButton = v end
117
118
  # @see applyNumberFormat
118
- def applyNumberFormat=(v) Axlsx::validate_boolean v; @applyNumberFormat = v end
119
+ def applyNumberFormat=(v) Axlsx.validate_boolean v; @applyNumberFormat = v end
119
120
  # @see applyFont
120
- def applyFont=(v) Axlsx::validate_boolean v; @applyFont = v end
121
+ def applyFont=(v) Axlsx.validate_boolean v; @applyFont = v end
121
122
  # @see applyFill
122
- def applyFill=(v) Axlsx::validate_boolean v; @applyFill = v end
123
+ def applyFill=(v) Axlsx.validate_boolean v; @applyFill = v end
123
124
 
124
125
  # @see applyBorder
125
- def applyBorder=(v) Axlsx::validate_boolean v; @applyBorder = v end
126
+ def applyBorder=(v) Axlsx.validate_boolean v; @applyBorder = v end
126
127
 
127
128
  # @see applyAlignment
128
- def applyAlignment=(v) Axlsx::validate_boolean v; @applyAlignment = v end
129
+ def applyAlignment=(v) Axlsx.validate_boolean v; @applyAlignment = v end
129
130
 
130
131
  # @see applyProtection
131
- def applyProtection=(v) Axlsx::validate_boolean v; @applyProtection = v end
132
+ def applyProtection=(v) Axlsx.validate_boolean v; @applyProtection = v end
132
133
 
133
134
  # Serializes the object
134
135
  # @param [String] str
135
136
  # @return [String]
136
- def to_xml_string(str = '')
137
+ def to_xml_string(str = +'')
137
138
  str << '<xf '
138
139
  serialized_attributes str
139
140
  str << '>'
140
- alignment.to_xml_string(str) if self.alignment
141
- protection.to_xml_string(str) if self.protection
141
+ alignment.to_xml_string(str) if alignment
142
+ protection.to_xml_string(str) if protection
142
143
  str << '</xf>'
143
144
  end
144
-
145
-
146
145
  end
147
146
  end