caxlsx 4.0.0 → 4.4.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 (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +48 -12
  3. data/README.md +18 -9
  4. data/Rakefile +2 -9
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +6 -3
  7. data/lib/axlsx/content_type/content_type.rb +4 -4
  8. data/lib/axlsx/content_type/default.rb +4 -1
  9. data/lib/axlsx/content_type/override.rb +4 -1
  10. data/lib/axlsx/doc_props/app.rb +91 -24
  11. data/lib/axlsx/drawing/area_chart.rb +3 -3
  12. data/lib/axlsx/drawing/area_series.rb +10 -4
  13. data/lib/axlsx/drawing/ax_data_source.rb +1 -1
  14. data/lib/axlsx/drawing/axes.rb +1 -1
  15. data/lib/axlsx/drawing/axis.rb +25 -7
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -4
  17. data/lib/axlsx/drawing/bar_chart.rb +14 -4
  18. data/lib/axlsx/drawing/bar_series.rb +14 -5
  19. data/lib/axlsx/drawing/bubble_chart.rb +2 -2
  20. data/lib/axlsx/drawing/bubble_series.rb +2 -2
  21. data/lib/axlsx/drawing/cat_axis.rb +23 -8
  22. data/lib/axlsx/drawing/chart.rb +33 -8
  23. data/lib/axlsx/drawing/d_lbls.rb +9 -8
  24. data/lib/axlsx/drawing/drawing.rb +50 -49
  25. data/lib/axlsx/drawing/hyperlink.rb +13 -4
  26. data/lib/axlsx/drawing/line_3D_chart.rb +3 -3
  27. data/lib/axlsx/drawing/line_chart.rb +3 -3
  28. data/lib/axlsx/drawing/line_series.rb +10 -4
  29. data/lib/axlsx/drawing/marker.rb +19 -4
  30. data/lib/axlsx/drawing/num_val.rb +1 -1
  31. data/lib/axlsx/drawing/one_cell_anchor.rb +8 -2
  32. data/lib/axlsx/drawing/pic.rb +17 -8
  33. data/lib/axlsx/drawing/pie_3D_chart.rb +3 -3
  34. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  35. data/lib/axlsx/drawing/pie_series.rb +18 -6
  36. data/lib/axlsx/drawing/scaling.rb +18 -4
  37. data/lib/axlsx/drawing/scatter_chart.rb +2 -2
  38. data/lib/axlsx/drawing/scatter_series.rb +2 -2
  39. data/lib/axlsx/drawing/ser_axis.rb +11 -5
  40. data/lib/axlsx/drawing/series.rb +8 -2
  41. data/lib/axlsx/drawing/two_cell_anchor.rb +1 -1
  42. data/lib/axlsx/drawing/val_axis.rb +2 -2
  43. data/lib/axlsx/drawing/view_3D.rb +8 -2
  44. data/lib/axlsx/drawing/vml_shape.rb +1 -1
  45. data/lib/axlsx/package.rb +54 -21
  46. data/lib/axlsx/rels/relationship.rb +15 -5
  47. data/lib/axlsx/rels/relationships.rb +3 -3
  48. data/lib/axlsx/stylesheet/border.rb +12 -3
  49. data/lib/axlsx/stylesheet/border_pr.rb +16 -4
  50. data/lib/axlsx/stylesheet/cell_alignment.rb +39 -10
  51. data/lib/axlsx/stylesheet/cell_protection.rb +9 -2
  52. data/lib/axlsx/stylesheet/cell_style.rb +30 -7
  53. data/lib/axlsx/stylesheet/color.rb +10 -4
  54. data/lib/axlsx/stylesheet/dxf.rb +29 -6
  55. data/lib/axlsx/stylesheet/fill.rb +4 -1
  56. data/lib/axlsx/stylesheet/font.rb +59 -13
  57. data/lib/axlsx/stylesheet/gradient_fill.rb +9 -3
  58. data/lib/axlsx/stylesheet/gradient_stop.rb +9 -2
  59. data/lib/axlsx/stylesheet/num_fmt.rb +8 -2
  60. data/lib/axlsx/stylesheet/pattern_fill.rb +15 -3
  61. data/lib/axlsx/stylesheet/styles.rb +84 -43
  62. data/lib/axlsx/stylesheet/table_style.rb +15 -4
  63. data/lib/axlsx/stylesheet/table_style_element.rb +12 -3
  64. data/lib/axlsx/stylesheet/table_styles.rb +10 -3
  65. data/lib/axlsx/stylesheet/theme.rb +163 -0
  66. data/lib/axlsx/stylesheet/xf.rb +70 -16
  67. data/lib/axlsx/util/accessors.rb +9 -7
  68. data/lib/axlsx/util/buffered_zip_output_stream.rb +6 -2
  69. data/lib/axlsx/util/constants.rb +14 -2
  70. data/lib/axlsx/util/mime_type_utils.rb +72 -13
  71. data/lib/axlsx/util/serialized_attributes.rb +2 -2
  72. data/lib/axlsx/util/simple_typed_list.rb +26 -14
  73. data/lib/axlsx/util/storage.rb +4 -4
  74. data/lib/axlsx/util/uri_utils.rb +70 -0
  75. data/lib/axlsx/util/validators.rb +6 -6
  76. data/lib/axlsx/version.rb +1 -1
  77. data/lib/axlsx/workbook/defined_name.rb +2 -1
  78. data/lib/axlsx/workbook/defined_names.rb +1 -1
  79. data/lib/axlsx/workbook/shared_strings_table.rb +3 -3
  80. data/lib/axlsx/workbook/workbook.rb +87 -67
  81. data/lib/axlsx/workbook/workbook_view.rb +1 -1
  82. data/lib/axlsx/workbook/workbook_views.rb +1 -1
  83. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +4 -4
  84. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +5 -3
  85. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +4 -4
  86. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +1 -1
  87. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +2 -2
  88. data/lib/axlsx/workbook/worksheet/border_creator.rb +4 -4
  89. data/lib/axlsx/workbook/worksheet/cell.rb +40 -20
  90. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
  91. data/lib/axlsx/workbook/worksheet/cfvo.rb +8 -2
  92. data/lib/axlsx/workbook/worksheet/col.rb +23 -9
  93. data/lib/axlsx/workbook/worksheet/col_breaks.rb +1 -1
  94. data/lib/axlsx/workbook/worksheet/cols.rb +1 -1
  95. data/lib/axlsx/workbook/worksheet/comment.rb +2 -2
  96. data/lib/axlsx/workbook/worksheet/comments.rb +1 -1
  97. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +9 -3
  98. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +70 -15
  99. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +3 -3
  100. data/lib/axlsx/workbook/worksheet/data_validation.rb +53 -14
  101. data/lib/axlsx/workbook/worksheet/data_validations.rb +3 -3
  102. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +2 -2
  103. data/lib/axlsx/workbook/worksheet/dimension.rb +1 -1
  104. data/lib/axlsx/workbook/worksheet/header_footer.rb +1 -1
  105. data/lib/axlsx/workbook/worksheet/icon_set.rb +17 -5
  106. data/lib/axlsx/workbook/worksheet/merged_cells.rb +1 -1
  107. data/lib/axlsx/workbook/worksheet/outline_pr.rb +1 -1
  108. data/lib/axlsx/workbook/worksheet/page_margins.rb +30 -7
  109. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -2
  110. data/lib/axlsx/workbook/worksheet/page_setup.rb +32 -9
  111. data/lib/axlsx/workbook/worksheet/pane.rb +9 -2
  112. data/lib/axlsx/workbook/worksheet/pivot_table.rb +30 -6
  113. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +1 -1
  114. data/lib/axlsx/workbook/worksheet/print_options.rb +1 -0
  115. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +1 -1
  116. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +31 -11
  117. data/lib/axlsx/workbook/worksheet/row.rb +5 -2
  118. data/lib/axlsx/workbook/worksheet/row_breaks.rb +1 -1
  119. data/lib/axlsx/workbook/worksheet/selection.rb +8 -2
  120. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +1 -0
  121. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +1 -1
  122. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -1
  123. data/lib/axlsx/workbook/worksheet/sheet_view.rb +30 -9
  124. data/lib/axlsx/workbook/worksheet/table_style_info.rb +3 -2
  125. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  126. data/lib/axlsx/workbook/worksheet/worksheet.rb +28 -14
  127. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -4
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +3 -2
  130. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +2 -2
  131. data/lib/axlsx.rb +46 -30
  132. data/lib/caxlsx.rb +1 -1
  133. metadata +13 -52
@@ -1,27 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
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'
4
+ require_relative 'border'
5
+ require_relative 'border_pr'
6
+ require_relative 'cell_alignment'
7
+ require_relative 'cell_style'
8
+ require_relative 'color'
9
+ require_relative 'fill'
10
+ require_relative 'font'
11
+ require_relative 'gradient_fill'
12
+ require_relative 'gradient_stop'
13
+ require_relative 'num_fmt'
14
+ require_relative 'pattern_fill'
15
+ require_relative 'table_style'
16
+ require_relative 'table_styles'
17
+ require_relative 'table_style_element'
18
+ require_relative 'theme'
19
+ require_relative 'dxf'
20
+ require_relative 'xf'
21
+ require_relative 'cell_protection'
21
22
 
22
23
  # The Styles class manages worksheet styles
23
24
  # 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.
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.
25
+ # All portions of the stylesheet are implemented here exception colors, which specify legacy and modified palette colors, and exLst, which is used as a future feature data storage area.
25
26
  # @see Office Open XML Part 1 18.8.11 for gory details on how this stuff gets put together
26
27
  # @see Styles#add_style
27
28
  # @note The recommended way to manage styles is with add_style
@@ -156,7 +157,7 @@ module Axlsx
156
157
  # ws = p.workbook.add_worksheet
157
158
  #
158
159
  # # black text on a white background at 14pt with thin borders!
159
- # title = ws.styles.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
160
+ # title = ws.styles.add_style(:bg_color => "FFFF0000", :fg_color=>"FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
160
161
  #
161
162
  # ws.add_row ["Least Popular Pets"]
162
163
  # ws.add_row ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
@@ -174,7 +175,7 @@ module Axlsx
174
175
  #
175
176
  # # define your styles
176
177
  # title = ws.styles.add_style(:bg_color => "FFFF0000",
177
- # :fg_color=>"#FF000000",
178
+ # :fg_color=>"FF000000",
178
179
  # :border=>Axlsx::STYLE_THIN_BORDER,
179
180
  # :alignment=>{:horizontal => :center})
180
181
  #
@@ -209,10 +210,10 @@ module Axlsx
209
210
  #
210
211
  # # define your styles
211
212
  # profitable = wb.styles.add_style(:bg_color => "FFFF0000",
212
- # :fg_color=>"#FF000000",
213
+ # :fg_color=>"FF000000",
213
214
  # :type => :dxf)
214
215
  #
215
- # ws.add_row ["Genreated At:", Time.now], :styles=>[nil, date_time]
216
+ # ws.add_row ["Generated At:", Time.now], :styles=>[nil, date_time]
216
217
  # ws.add_row ["Previous Year Quarterly Profits (JPY)"], :style=>title
217
218
  # ws.add_row ["Quarter", "Profit", "% of Total"], :style=>title
218
219
  # ws.add_row ["Q1", 4000, 40], :style=>[title, currency, percent]
@@ -245,7 +246,7 @@ module Axlsx
245
246
 
246
247
  font_defaults = { name: @fonts.first.name, sz: @fonts.first.sz, family: @fonts.first.family }
247
248
 
248
- raw_style = { type: :xf }.merge(font_defaults).merge(options)
249
+ raw_style = { type: :xf }.merge(font_defaults, options)
249
250
 
250
251
  if raw_style[:format_code]
251
252
  raw_style.delete(:num_fmt)
@@ -275,7 +276,7 @@ module Axlsx
275
276
  if options[:type] == :xf
276
277
  xf_index = (cellXfs << style)
277
278
 
278
- # Add styles to style_index cache for re-use
279
+ # Add styles to style_index cache for reuse
279
280
  style_index[xf_index] = raw_style
280
281
 
281
282
  xf_index
@@ -298,7 +299,7 @@ module Axlsx
298
299
 
299
300
  # parses add_style options for alignment
300
301
  # noop if options hash does not include :alignment key
301
- # @option options [Hash] alignment A hash of options to prive the CellAlignment intializer
302
+ # @option options [Hash] alignment A hash of options to prive the CellAlignment initializer
302
303
  # @return [CellAlignment]
303
304
  # @see CellAlignment
304
305
  def parse_alignment_options(options = {})
@@ -325,27 +326,60 @@ module Axlsx
325
326
  def parse_font_options(options = {})
326
327
  return if (options.keys & [:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name]).empty?
327
328
 
328
- Axlsx.instance_values_for(fonts.first).each do |key, value|
329
- # Thanks for that 1.8.7 - cant do a simple merge...
330
- options[key.to_sym] = value unless options.key?(key.to_sym)
331
- end
332
- font = Font.new(options)
329
+ font = Font.new(Axlsx.instance_values_for(fonts.first).merge(options))
333
330
  font.color = Color.new(rgb: options[:fg_color]) if options[:fg_color]
334
331
  font.name = options[:font_name] if options[:font_name]
335
332
  options[:type] == :dxf ? font : fonts << font
336
333
  end
337
334
 
338
335
  # parses add_style options for fills. If the options hash contains :type => :dxf we return a Fill object. If not, we return the index of the fill after being added to the fills collection.
339
- # @note noop if :bg_color is not specified in options
340
- # @option options [String] bg_color The rgb color to apply to the fill
336
+ # @note noop unless at least one of the documented attributes is specified in options
337
+ # @option options [String] bg_color The rgb color to apply to the fill. An alias for pattern_bg_color if you need only a solid background
338
+ # @option options [String] pattern_type The fill pattern to apply to the fill
339
+ # @option options [String] pattern_bg_color The rgb color to apply to the fill as the first color
340
+ # @option options [String] pattern_fg_color The rgb color to apply to the fill as the second color
341
341
  # @return [Fill|Integer]
342
342
  def parse_fill_options(options = {})
343
- return unless options[:bg_color]
343
+ return unless options[:bg_color] || options[:pattern_type] || options[:pattern_bg_color] || options[:pattern_fg_color]
344
344
 
345
- color = Color.new(rgb: options[:bg_color])
345
+ pattern_type = options[:pattern_type] || :solid
346
346
  dxf = options[:type] == :dxf
347
- color_key = dxf ? :bgColor : :fgColor
348
- pattern = PatternFill.new(:patternType => :solid, color_key => color)
347
+
348
+ pattern_options = {
349
+ patternType: pattern_type
350
+ }
351
+
352
+ if options[:pattern_bg_color] && options[:bg_color]
353
+ warn 'Both `bg_color` and `pattern_bg_color` got defined. To get a solid background without defining it in `patter_type`, use only `bg_color`, otherwise use only `pattern_bg_color` to avoid confusion.'
354
+ end
355
+
356
+ bg_color = options[:pattern_bg_color] || options[:bg_color]
357
+ fg_color = options[:pattern_fg_color]
358
+
359
+ # Both bgColor and fgColor happens to configure the background of the cell.
360
+ # One of them sets the "background" of the cell, while the other one is
361
+ # responsible for the "pattern" of the cell. When you pick "solid" pattern for
362
+ # a normal xf style, then it's a rectangle covering all bgColor with fgColor,
363
+ # which means we need to to set the given background color to fgColor as well.
364
+ # For some reason I wasn't able find, it works the opposite for dxf styles
365
+ # (differential formatting records), so to get the expected color, we need
366
+ # to put it into bgColor. We only need these cross-assignments when using
367
+ # "solid" pattern and the user provided only one color to get the least
368
+ # amount of surprise
369
+
370
+ if bg_color
371
+ pattern_options[:bgColor] = Color.new(rgb: bg_color)
372
+ elsif pattern_type == :solid && fg_color
373
+ pattern_options[:bgColor] = Color.new(rgb: fg_color)
374
+ end
375
+
376
+ if fg_color
377
+ pattern_options[:fgColor] = Color.new(rgb: fg_color)
378
+ elsif pattern_type == :solid && bg_color
379
+ pattern_options[:fgColor] = Color.new(rgb: bg_color)
380
+ end
381
+
382
+ pattern = PatternFill.new(pattern_options)
349
383
  fill = Fill.new(pattern)
350
384
  dxf ? fill : fills << fill
351
385
  end
@@ -364,7 +398,7 @@ module Axlsx
364
398
  # { :border => { :style => :thick, :color => "FFFF0000", :edges => [:top, :bottom] }
365
399
  # @return [Border|Integer]
366
400
  def parse_border_options(options = {})
367
- if options[:border].nil? && Border::EDGES.all? { |x| options["border_#{x}".to_sym].nil? }
401
+ if options[:border].nil? && Border::EDGES.all? { |x| options[:"border_#{x}"].nil? }
368
402
  return nil
369
403
  end
370
404
 
@@ -409,7 +443,7 @@ module Axlsx
409
443
  end
410
444
 
411
445
  Border::EDGES.each do |edge|
412
- val = options["border_#{edge}".to_sym]
446
+ val = options[:"border_#{edge}"]
413
447
 
414
448
  if val
415
449
  borders_array << val.merge(edges: [edge])
@@ -430,8 +464,8 @@ module Axlsx
430
464
  end
431
465
  end
432
466
 
433
- if options["border_#{edge}".to_sym]
434
- edge_b_opts = edge_b_opts.merge(options["border_#{edge}".to_sym])
467
+ if options[:"border_#{edge}"]
468
+ edge_b_opts = edge_b_opts.merge(options[:"border_#{edge}"])
435
469
  skip_edge = false
436
470
  end
437
471
 
@@ -472,7 +506,12 @@ module Axlsx
472
506
  # If this is a standard xf we pull from numFmts the highest current and increment for num_fmt
473
507
  options[:num_fmt] ||= (@numFmts.map(&:numFmtId).max + 1) if options[:type] != :dxf
474
508
  numFmt = NumFmt.new(numFmtId: options[:num_fmt] || 0, formatCode: options[:format_code].to_s)
475
- options[:type] == :dxf ? numFmt : (numFmts << numFmt; numFmt.numFmtId)
509
+ if options[:type] == :dxf
510
+ numFmt
511
+ else
512
+ numFmts << numFmt
513
+ numFmt.numFmtId
514
+ end
476
515
  else
477
516
  options[:num_fmt]
478
517
  end
@@ -534,8 +573,10 @@ module Axlsx
534
573
  @cellXfs << Xf.new(borderId: 0, xfId: 0, numFmtId: 14, fontId: 0, fillId: 0, applyNumberFormat: 1)
535
574
  @cellXfs.lock
536
575
 
537
- @dxfs = SimpleTypedList.new(Dxf, "dxfs"); @dxfs.lock
538
- @tableStyles = TableStyles.new(defaultTableStyle: "TableStyleMedium9", defaultPivotStyle: "PivotStyleLight16"); @tableStyles.lock
576
+ @dxfs = SimpleTypedList.new(Dxf, "dxfs")
577
+ @dxfs.lock
578
+ @tableStyles = TableStyles.new(defaultTableStyle: "TableStyleMedium9", defaultPivotStyle: "PivotStyleLight16")
579
+ @tableStyles.lock
539
580
  end
540
581
  end
541
582
  end
@@ -15,7 +15,7 @@ module Axlsx
15
15
  def initialize(name, options = {})
16
16
  self.name = name
17
17
  parse_options options
18
- super TableStyleElement
18
+ super(TableStyleElement)
19
19
  end
20
20
 
21
21
  serializable_attributes :name, :pivot, :table
@@ -33,11 +33,22 @@ 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)
37
+ Axlsx.validate_string v
38
+ @name = v
39
+ end
40
+
37
41
  # @see pivot
38
- def pivot=(v) Axlsx.validate_boolean v; @pivot = v end
42
+ def pivot=(v)
43
+ Axlsx.validate_boolean v
44
+ @pivot = v
45
+ end
46
+
39
47
  # @see table
40
- def table=(v) Axlsx.validate_boolean v; @table = v end
48
+ def table=(v)
49
+ Axlsx.validate_boolean v
50
+ @table = v
51
+ end
41
52
 
42
53
  # Serializes the object
43
54
  # @param [String] str
@@ -58,13 +58,22 @@ 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)
62
+ Axlsx.validate_table_element_type v
63
+ @type = v
64
+ end
62
65
 
63
66
  # @see size
64
- def size=(v) Axlsx.validate_unsigned_int v; @size = v end
67
+ def size=(v)
68
+ Axlsx.validate_unsigned_int v
69
+ @size = v
70
+ end
65
71
 
66
72
  # @see dxfId
67
- def dxfId=(v) Axlsx.validate_unsigned_int v; @dxfId = v end
73
+ def dxfId=(v)
74
+ Axlsx.validate_unsigned_int v
75
+ @dxfId = v
76
+ end
68
77
 
69
78
  # Serializes the object
70
79
  # @param [String] str
@@ -12,7 +12,7 @@ module Axlsx
12
12
  def initialize(options = {})
13
13
  @defaultTableStyle = options[:defaultTableStyle] || "TableStyleMedium9"
14
14
  @defaultPivotStyle = options[:defaultPivotStyle] || "PivotStyleLight16"
15
- super TableStyle
15
+ super(TableStyle)
16
16
  end
17
17
 
18
18
  serializable_attributes :defaultTableStyle, :defaultPivotStyle
@@ -26,9 +26,16 @@ module Axlsx
26
26
  attr_reader :defaultPivotStyle
27
27
 
28
28
  # @see defaultTableStyle
29
- def defaultTableStyle=(v) Axlsx.validate_string(v); @defaultTableStyle = v; end
29
+ def defaultTableStyle=(v)
30
+ Axlsx.validate_string(v)
31
+ @defaultTableStyle = v
32
+ end
33
+
30
34
  # @see defaultPivotStyle
31
- def defaultPivotStyle=(v) Axlsx.validate_string(v); @defaultPivotStyle = v; end
35
+ def defaultPivotStyle=(v)
36
+ Axlsx.validate_string(v)
37
+ @defaultPivotStyle = v
38
+ end
32
39
 
33
40
  # Serializes the object
34
41
  # @param [String] str
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Axlsx
4
+ # Theme represents the theme part of the package and is responsible for
5
+ # generating the default Office theme that is required for encryption compatibility
6
+ class Theme
7
+ # The part name of this theme
8
+ # @return [String]
9
+ def pn
10
+ THEME_PN
11
+ end
12
+
13
+ # Serializes the default theme to XML
14
+ # @param [String] str
15
+ # @return [String]
16
+ def to_xml_string(str = +'')
17
+ str << <<~XML.delete("\n")
18
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
19
+ <a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme">
20
+ <a:themeElements>
21
+ <a:clrScheme name="Office">
22
+ <a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1>
23
+ <a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1>
24
+ <a:dk2><a:srgbClr val="1F497D"/></a:dk2>
25
+ <a:lt2><a:srgbClr val="EEECE1"/></a:lt2>
26
+ <a:accent1><a:srgbClr val="4F81BD"/></a:accent1>
27
+ <a:accent2><a:srgbClr val="C0504D"/></a:accent2>
28
+ <a:accent3><a:srgbClr val="9BBB59"/></a:accent3>
29
+ <a:accent4><a:srgbClr val="8064A2"/></a:accent4>
30
+ <a:accent5><a:srgbClr val="4BACC6"/></a:accent5>
31
+ <a:accent6><a:srgbClr val="F79646"/></a:accent6>
32
+ <a:hlink><a:srgbClr val="0000FF"/></a:hlink>
33
+ <a:folHlink><a:srgbClr val="800080"/></a:folHlink>
34
+ </a:clrScheme>
35
+
36
+ <a:fontScheme name="Office">
37
+ <a:majorFont>
38
+ <a:latin typeface="Cambria"/>
39
+ <a:ea typeface=""/>
40
+ <a:cs typeface=""/>
41
+ </a:majorFont>
42
+ <a:minorFont>
43
+ <a:latin typeface="Calibri"/>
44
+ <a:ea typeface=""/>
45
+ <a:cs typeface=""/>
46
+ </a:minorFont>
47
+ </a:fontScheme>
48
+
49
+ <a:fmtScheme name="Office">
50
+ <a:fillStyleLst>
51
+ <a:solidFill><a:schemeClr val="phClr"/></a:solidFill>
52
+ <a:gradFill rotWithShape="1">
53
+ <a:gsLst>
54
+ <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/><a:satMod val="300000"/></a:schemeClr></a:gs>
55
+ <a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"/><a:satMod val="300000"/></a:schemeClr></a:gs>
56
+ <a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
57
+ </a:gsLst>
58
+ <a:lin ang="16200000" scaled="1"/>
59
+ </a:gradFill>
60
+ <a:gradFill rotWithShape="1">
61
+ <a:gsLst>
62
+ <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="100000"/><a:shade val="100000"/><a:satMod val="130000"/></a:schemeClr></a:gs>
63
+ <a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="50000"/><a:shade val="100000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
64
+ </a:gsLst>
65
+ <a:lin ang="16200000" scaled="false"/>
66
+ </a:gradFill>
67
+ </a:fillStyleLst>
68
+
69
+ <a:lnStyleLst>
70
+ <a:ln w="9525" cap="flat" cmpd="sng" algn="ctr">
71
+ <a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"/><a:satMod val="105000"/></a:schemeClr></a:solidFill>
72
+ <a:prstDash val="solid"/>
73
+ </a:ln>
74
+ <a:ln w="25400" cap="flat" cmpd="sng" algn="ctr">
75
+ <a:solidFill><a:schemeClr val="phClr"/></a:solidFill>
76
+ <a:prstDash val="solid"/>
77
+ </a:ln>
78
+ <a:ln w="38100" cap="flat" cmpd="sng" algn="ctr">
79
+ <a:solidFill><a:schemeClr val="phClr"/></a:solidFill>
80
+ <a:prstDash val="solid"/>
81
+ </a:ln>
82
+ </a:lnStyleLst>
83
+
84
+ <a:effectStyleLst>
85
+ <a:effectStyle>
86
+ <a:effectLst>
87
+ <a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="false">
88
+ <a:srgbClr val="000000"><a:alpha val="38000"/></a:srgbClr>
89
+ </a:outerShdw>
90
+ </a:effectLst>
91
+ </a:effectStyle>
92
+ <a:effectStyle>
93
+ <a:effectLst>
94
+ <a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="false">
95
+ <a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr>
96
+ </a:outerShdw>
97
+ </a:effectLst>
98
+ </a:effectStyle>
99
+ <a:effectStyle>
100
+ <a:effectLst>
101
+ <a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="false">
102
+ <a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr>
103
+ </a:outerShdw>
104
+ </a:effectLst>
105
+ <a:scene3d>
106
+ <a:camera prst="orthographicFront"><a:rot lat="0" lon="0" rev="0"/></a:camera>
107
+ <a:lightRig rig="threePt" dir="t"><a:rot lat="0" lon="0" rev="1200000"/></a:lightRig>
108
+ </a:scene3d>
109
+ <a:sp3d><a:bevelT w="63500" h="25400"/></a:sp3d>
110
+ </a:effectStyle>
111
+ </a:effectStyleLst>
112
+
113
+ <a:bgFillStyleLst>
114
+ <a:solidFill><a:schemeClr val="phClr"/></a:solidFill>
115
+ <a:gradFill rotWithShape="1">
116
+ <a:gsLst>
117
+ <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
118
+ <a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"/><a:shade val="99000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
119
+ <a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="20000"/><a:satMod val="255000"/></a:schemeClr></a:gs>
120
+ </a:gsLst>
121
+ <a:path path="circle"><a:fillToRect l="50000" t="-80000" r="50000" b="180000"/></a:path>
122
+ </a:gradFill>
123
+ <a:gradFill rotWithShape="1">
124
+ <a:gsLst>
125
+ <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/><a:satMod val="300000"/></a:schemeClr></a:gs>
126
+ <a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="30000"/><a:satMod val="200000"/></a:schemeClr></a:gs>
127
+ </a:gsLst>
128
+ <a:path path="circle"><a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path>
129
+ </a:gradFill>
130
+ </a:bgFillStyleLst>
131
+ </a:fmtScheme>
132
+ </a:themeElements>
133
+
134
+ <a:objectDefaults>
135
+ <a:spDef>
136
+ <a:spPr/>
137
+ <a:bodyPr/>
138
+ <a:lstStyle/>
139
+ <a:style>
140
+ <a:lnRef idx="1"><a:schemeClr val="accent1"/></a:lnRef>
141
+ <a:fillRef idx="3"><a:schemeClr val="accent1"/></a:fillRef>
142
+ <a:effectRef idx="2"><a:schemeClr val="accent1"/></a:effectRef>
143
+ <a:fontRef idx="minor"><a:schemeClr val="lt1"/></a:fontRef>
144
+ </a:style>
145
+ </a:spDef>
146
+ <a:lnDef>
147
+ <a:spPr/>
148
+ <a:bodyPr/>
149
+ <a:lstStyle/>
150
+ <a:style>
151
+ <a:lnRef idx="2"><a:schemeClr val="accent1"/></a:lnRef>
152
+ <a:fillRef idx="0"><a:schemeClr val="accent1"/></a:fillRef>
153
+ <a:effectRef idx="1"><a:schemeClr val="accent1"/></a:effectRef>
154
+ <a:fontRef idx="minor"><a:schemeClr val="tx1"/></a:fontRef>
155
+ </a:style>
156
+ </a:lnDef>
157
+ </a:objectDefaults>
158
+ <a:extraClrSchemeLst/>
159
+ </a:theme>
160
+ XML
161
+ end
162
+ end
163
+ end
@@ -8,6 +8,7 @@ module Axlsx
8
8
 
9
9
  include Axlsx::SerializedAttributes
10
10
  include Axlsx::OptionsParser
11
+
11
12
  # Creates a new Xf object
12
13
  # @option options [Integer] numFmtId
13
14
  # @option options [Integer] fontId
@@ -62,7 +63,7 @@ module Axlsx
62
63
  # @return [Integer]
63
64
  attr_reader :xfId
64
65
 
65
- # indecates if text should be prefixed by a single quote in the cell
66
+ # indicates if text should be prefixed by a single quote in the cell
66
67
  # @return [Boolean]
67
68
  attr_reader :quotePrefix
68
69
 
@@ -95,41 +96,94 @@ module Axlsx
95
96
  attr_reader :applyProtection
96
97
 
97
98
  # @see Xf#alignment
98
- def alignment=(v) DataTypeValidator.validate "Xf.alignment", CellAlignment, v; @alignment = v end
99
+ def alignment=(v)
100
+ DataTypeValidator.validate "Xf.alignment", CellAlignment, v
101
+ @alignment = v
102
+ end
99
103
 
100
104
  # @see protection
101
- def protection=(v) DataTypeValidator.validate "Xf.protection", CellProtection, v; @protection = v end
105
+ def protection=(v)
106
+ DataTypeValidator.validate "Xf.protection", CellProtection, v
107
+ @protection = v
108
+ end
102
109
 
103
110
  # @see numFmtId
104
- def numFmtId=(v) Axlsx.validate_unsigned_int v; @numFmtId = v end
111
+ def numFmtId=(v)
112
+ Axlsx.validate_unsigned_int v
113
+ @numFmtId = v
114
+ end
105
115
 
106
116
  # @see fontId
107
- def fontId=(v) Axlsx.validate_unsigned_int v; @fontId = v end
117
+ def fontId=(v)
118
+ Axlsx.validate_unsigned_int v
119
+ @fontId = v
120
+ end
121
+
108
122
  # @see fillId
109
- def fillId=(v) Axlsx.validate_unsigned_int v; @fillId = v end
123
+ def fillId=(v)
124
+ Axlsx.validate_unsigned_int v
125
+ @fillId = v
126
+ end
127
+
110
128
  # @see borderId
111
- def borderId=(v) Axlsx.validate_unsigned_int v; @borderId = v end
129
+ def borderId=(v)
130
+ Axlsx.validate_unsigned_int v
131
+ @borderId = v
132
+ end
133
+
112
134
  # @see xfId
113
- def xfId=(v) Axlsx.validate_unsigned_int v; @xfId = v end
135
+ def xfId=(v)
136
+ Axlsx.validate_unsigned_int v
137
+ @xfId = v
138
+ end
139
+
114
140
  # @see quotePrefix
115
- def quotePrefix=(v) Axlsx.validate_boolean v; @quotePrefix = v end
141
+ def quotePrefix=(v)
142
+ Axlsx.validate_boolean v
143
+ @quotePrefix = v
144
+ end
145
+
116
146
  # @see pivotButton
117
- def pivotButton=(v) Axlsx.validate_boolean v; @pivotButton = v end
147
+ def pivotButton=(v)
148
+ Axlsx.validate_boolean v
149
+ @pivotButton = v
150
+ end
151
+
118
152
  # @see applyNumberFormat
119
- def applyNumberFormat=(v) Axlsx.validate_boolean v; @applyNumberFormat = v end
153
+ def applyNumberFormat=(v)
154
+ Axlsx.validate_boolean v
155
+ @applyNumberFormat = v
156
+ end
157
+
120
158
  # @see applyFont
121
- def applyFont=(v) Axlsx.validate_boolean v; @applyFont = v end
159
+ def applyFont=(v)
160
+ Axlsx.validate_boolean v
161
+ @applyFont = v
162
+ end
163
+
122
164
  # @see applyFill
123
- def applyFill=(v) Axlsx.validate_boolean v; @applyFill = v end
165
+ def applyFill=(v)
166
+ Axlsx.validate_boolean v
167
+ @applyFill = v
168
+ end
124
169
 
125
170
  # @see applyBorder
126
- def applyBorder=(v) Axlsx.validate_boolean v; @applyBorder = v end
171
+ def applyBorder=(v)
172
+ Axlsx.validate_boolean v
173
+ @applyBorder = v
174
+ end
127
175
 
128
176
  # @see applyAlignment
129
- def applyAlignment=(v) Axlsx.validate_boolean v; @applyAlignment = v end
177
+ def applyAlignment=(v)
178
+ Axlsx.validate_boolean v
179
+ @applyAlignment = v
180
+ end
130
181
 
131
182
  # @see applyProtection
132
- def applyProtection=(v) Axlsx.validate_boolean v; @applyProtection = v end
183
+ def applyProtection=(v)
184
+ Axlsx.validate_boolean v
185
+ @applyProtection = v
186
+ end
133
187
 
134
188
  # Serializes the object
135
189
  # @param [String] str
@@ -23,7 +23,7 @@ module Axlsx
23
23
  validated_attr_accessor(symbols, :validate_string)
24
24
  end
25
25
 
26
- # Creates one or more usigned integer attr_accessors
26
+ # Creates one or more unsigned integer attr_accessors
27
27
  # @param [Array] symbols An array of symbols representing the
28
28
  # names of the attributes you will add to your class
29
29
  def unsigned_int_attr_accessor(*symbols)
@@ -44,19 +44,21 @@ module Axlsx
44
44
  validated_attr_accessor(symbols, :validate_boolean)
45
45
  end
46
46
 
47
- # Template for defining validated write accessors
48
- SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end"
49
-
50
47
  # Creates the reader and writer access methods
51
- # @param [Array] symbols The names of the attributes to create
52
- # @param [String] validator The axlsx validation method to use when
48
+ # @param [Array<Symbol, String>] symbols The names of the attributes to create
49
+ # @param [Symbol|String] validator The axlsx validation method to use when
53
50
  # validating assignation.
54
51
  # @see lib/axlsx/util/validators.rb
55
52
  def validated_attr_accessor(symbols, validator)
56
53
  symbols.each do |symbol|
57
54
  attr_reader symbol
58
55
 
59
- module_eval(format(SETTER, symbol, validator, symbol), __FILE__, __LINE__)
56
+ module_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
57
+ def #{symbol}=(value) # def name=(value)
58
+ Axlsx.#{validator} value # Axlsx.validate_string value
59
+ @#{symbol} = value # @name = value
60
+ end # end
61
+ RUBY_EVAL
60
62
  end
61
63
  end
62
64
  end