caxlsx 4.0.0 → 4.2.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 (122) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -12
  3. data/README.md +1 -1
  4. data/examples/generate.rb +3 -1
  5. data/lib/axlsx/content_type/abstract_content_type.rb +6 -3
  6. data/lib/axlsx/content_type/content_type.rb +4 -4
  7. data/lib/axlsx/content_type/default.rb +4 -1
  8. data/lib/axlsx/content_type/override.rb +4 -1
  9. data/lib/axlsx/doc_props/app.rb +91 -24
  10. data/lib/axlsx/drawing/area_chart.rb +3 -3
  11. data/lib/axlsx/drawing/area_series.rb +10 -4
  12. data/lib/axlsx/drawing/ax_data_source.rb +1 -1
  13. data/lib/axlsx/drawing/axes.rb +1 -1
  14. data/lib/axlsx/drawing/axis.rb +25 -7
  15. data/lib/axlsx/drawing/bar_3D_chart.rb +3 -3
  16. data/lib/axlsx/drawing/bar_chart.rb +3 -3
  17. data/lib/axlsx/drawing/bar_series.rb +14 -5
  18. data/lib/axlsx/drawing/bubble_chart.rb +2 -2
  19. data/lib/axlsx/drawing/bubble_series.rb +2 -2
  20. data/lib/axlsx/drawing/cat_axis.rb +23 -8
  21. data/lib/axlsx/drawing/chart.rb +32 -8
  22. data/lib/axlsx/drawing/d_lbls.rb +8 -8
  23. data/lib/axlsx/drawing/drawing.rb +50 -49
  24. data/lib/axlsx/drawing/hyperlink.rb +13 -4
  25. data/lib/axlsx/drawing/line_3D_chart.rb +3 -3
  26. data/lib/axlsx/drawing/line_chart.rb +3 -3
  27. data/lib/axlsx/drawing/line_series.rb +10 -4
  28. data/lib/axlsx/drawing/marker.rb +19 -4
  29. data/lib/axlsx/drawing/num_val.rb +1 -1
  30. data/lib/axlsx/drawing/one_cell_anchor.rb +8 -2
  31. data/lib/axlsx/drawing/pic.rb +17 -8
  32. data/lib/axlsx/drawing/pie_3D_chart.rb +3 -3
  33. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  34. data/lib/axlsx/drawing/pie_series.rb +18 -6
  35. data/lib/axlsx/drawing/scaling.rb +18 -4
  36. data/lib/axlsx/drawing/scatter_chart.rb +2 -2
  37. data/lib/axlsx/drawing/scatter_series.rb +2 -2
  38. data/lib/axlsx/drawing/ser_axis.rb +11 -5
  39. data/lib/axlsx/drawing/series.rb +8 -2
  40. data/lib/axlsx/drawing/two_cell_anchor.rb +1 -1
  41. data/lib/axlsx/drawing/val_axis.rb +2 -2
  42. data/lib/axlsx/drawing/view_3D.rb +8 -2
  43. data/lib/axlsx/package.rb +11 -11
  44. data/lib/axlsx/rels/relationship.rb +15 -5
  45. data/lib/axlsx/rels/relationships.rb +3 -3
  46. data/lib/axlsx/stylesheet/border.rb +12 -3
  47. data/lib/axlsx/stylesheet/border_pr.rb +15 -4
  48. data/lib/axlsx/stylesheet/cell_alignment.rb +39 -10
  49. data/lib/axlsx/stylesheet/cell_protection.rb +9 -2
  50. data/lib/axlsx/stylesheet/cell_style.rb +30 -7
  51. data/lib/axlsx/stylesheet/color.rb +10 -4
  52. data/lib/axlsx/stylesheet/dxf.rb +29 -6
  53. data/lib/axlsx/stylesheet/fill.rb +4 -1
  54. data/lib/axlsx/stylesheet/font.rb +59 -13
  55. data/lib/axlsx/stylesheet/gradient_fill.rb +9 -3
  56. data/lib/axlsx/stylesheet/gradient_stop.rb +9 -2
  57. data/lib/axlsx/stylesheet/num_fmt.rb +8 -2
  58. data/lib/axlsx/stylesheet/pattern_fill.rb +14 -3
  59. data/lib/axlsx/stylesheet/styles.rb +83 -43
  60. data/lib/axlsx/stylesheet/table_style.rb +15 -4
  61. data/lib/axlsx/stylesheet/table_style_element.rb +12 -3
  62. data/lib/axlsx/stylesheet/table_styles.rb +10 -3
  63. data/lib/axlsx/stylesheet/xf.rb +69 -16
  64. data/lib/axlsx/util/accessors.rb +9 -7
  65. data/lib/axlsx/util/constants.rb +2 -2
  66. data/lib/axlsx/util/serialized_attributes.rb +2 -2
  67. data/lib/axlsx/util/simple_typed_list.rb +25 -12
  68. data/lib/axlsx/util/storage.rb +4 -4
  69. data/lib/axlsx/util/validators.rb +1 -1
  70. data/lib/axlsx/version.rb +1 -1
  71. data/lib/axlsx/workbook/defined_name.rb +1 -1
  72. data/lib/axlsx/workbook/defined_names.rb +1 -1
  73. data/lib/axlsx/workbook/shared_strings_table.rb +3 -3
  74. data/lib/axlsx/workbook/workbook.rb +80 -67
  75. data/lib/axlsx/workbook/workbook_views.rb +1 -1
  76. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +4 -4
  77. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +5 -3
  78. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +3 -3
  79. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +1 -1
  80. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +2 -2
  81. data/lib/axlsx/workbook/worksheet/border_creator.rb +4 -4
  82. data/lib/axlsx/workbook/worksheet/cell.rb +37 -17
  83. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
  84. data/lib/axlsx/workbook/worksheet/cfvo.rb +8 -2
  85. data/lib/axlsx/workbook/worksheet/col.rb +22 -9
  86. data/lib/axlsx/workbook/worksheet/col_breaks.rb +1 -1
  87. data/lib/axlsx/workbook/worksheet/cols.rb +1 -1
  88. data/lib/axlsx/workbook/worksheet/comment.rb +2 -2
  89. data/lib/axlsx/workbook/worksheet/comments.rb +1 -1
  90. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +9 -3
  91. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +70 -15
  92. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +3 -3
  93. data/lib/axlsx/workbook/worksheet/data_validation.rb +53 -14
  94. data/lib/axlsx/workbook/worksheet/data_validations.rb +3 -3
  95. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +2 -2
  96. data/lib/axlsx/workbook/worksheet/dimension.rb +1 -1
  97. data/lib/axlsx/workbook/worksheet/icon_set.rb +17 -5
  98. data/lib/axlsx/workbook/worksheet/merged_cells.rb +1 -1
  99. data/lib/axlsx/workbook/worksheet/outline_pr.rb +1 -1
  100. data/lib/axlsx/workbook/worksheet/page_margins.rb +30 -7
  101. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -2
  102. data/lib/axlsx/workbook/worksheet/page_setup.rb +32 -9
  103. data/lib/axlsx/workbook/worksheet/pane.rb +8 -2
  104. data/lib/axlsx/workbook/worksheet/pivot_table.rb +29 -5
  105. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +1 -1
  106. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +1 -1
  107. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +31 -11
  108. data/lib/axlsx/workbook/worksheet/row.rb +5 -2
  109. data/lib/axlsx/workbook/worksheet/row_breaks.rb +1 -1
  110. data/lib/axlsx/workbook/worksheet/selection.rb +8 -2
  111. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +1 -1
  112. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -1
  113. data/lib/axlsx/workbook/worksheet/sheet_view.rb +30 -9
  114. data/lib/axlsx/workbook/worksheet/table_style_info.rb +2 -2
  115. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  116. data/lib/axlsx/workbook/worksheet/worksheet.rb +28 -14
  117. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +3 -3
  118. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +2 -2
  119. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +2 -2
  120. data/lib/axlsx.rb +44 -30
  121. data/lib/caxlsx.rb +1 -1
  122. metadata +10 -48
@@ -17,7 +17,7 @@ module Axlsx
17
17
 
18
18
  serializable_attributes :auto, :rgb, :tint
19
19
 
20
- # Determines if the color is system color dependant
20
+ # Determines if the color is system color dependent
21
21
  # @return [Boolean]
22
22
  attr_reader :auto
23
23
 
@@ -47,7 +47,10 @@ module Axlsx
47
47
  attr_reader :tint
48
48
 
49
49
  # @see auto
50
- def auto=(v) Axlsx.validate_boolean v; @auto = v end
50
+ def auto=(v)
51
+ Axlsx.validate_boolean v
52
+ @auto = v
53
+ end
51
54
 
52
55
  # @see color
53
56
  def rgb=(v)
@@ -61,12 +64,15 @@ module Axlsx
61
64
  end
62
65
 
63
66
  # @see tint
64
- def tint=(v) Axlsx.validate_float v; @tint = v end
67
+ def tint=(v)
68
+ Axlsx.validate_float v
69
+ @tint = v
70
+ end
65
71
 
66
72
  # This version does not support themes
67
73
  # def theme=(v) Axlsx::validate_unsigned_integer v; @theme = v end
68
74
 
69
- # Indexed colors are for backward compatability which I am choosing not to support
75
+ # Indexed colors are for backward compatibility which I am choosing not to support
70
76
  # def indexed=(v) Axlsx::validate_unsigned_integer v; @indexed = v end
71
77
 
72
78
  # Serializes the object
@@ -49,17 +49,40 @@ module Axlsx
49
49
  end
50
50
 
51
51
  # @see Dxf#alignment
52
- def alignment=(v) DataTypeValidator.validate "Dxf.alignment", CellAlignment, v; @alignment = v end
52
+ def alignment=(v)
53
+ DataTypeValidator.validate "Dxf.alignment", CellAlignment, v
54
+ @alignment = v
55
+ end
56
+
53
57
  # @see protection
54
- def protection=(v) DataTypeValidator.validate "Dxf.protection", CellProtection, v; @protection = v end
58
+ def protection=(v)
59
+ DataTypeValidator.validate "Dxf.protection", CellProtection, v
60
+ @protection = v
61
+ end
62
+
55
63
  # @see numFmt
56
- def numFmt=(v) DataTypeValidator.validate "Dxf.numFmt", NumFmt, v; @numFmt = v end
64
+ def numFmt=(v)
65
+ DataTypeValidator.validate "Dxf.numFmt", NumFmt, v
66
+ @numFmt = v
67
+ end
68
+
57
69
  # @see font
58
- def font=(v) DataTypeValidator.validate "Dxf.font", Font, v; @font = v end
70
+ def font=(v)
71
+ DataTypeValidator.validate "Dxf.font", Font, v
72
+ @font = v
73
+ end
74
+
59
75
  # @see border
60
- def border=(v) DataTypeValidator.validate "Dxf.border", Border, v; @border = v end
76
+ def border=(v)
77
+ DataTypeValidator.validate "Dxf.border", Border, v
78
+ @border = v
79
+ end
80
+
61
81
  # @see fill
62
- def fill=(v) DataTypeValidator.validate "Dxf.fill", Fill, v; @fill = v end
82
+ def fill=(v)
83
+ DataTypeValidator.validate "Dxf.fill", Fill, v
84
+ @fill = v
85
+ end
63
86
 
64
87
  # Serializes the object
65
88
  # @param [String] str
@@ -28,6 +28,9 @@ module Axlsx
28
28
  end
29
29
 
30
30
  # @see fill_type
31
- def fill_type=(v) DataTypeValidator.validate "Fill.fill_type", [PatternFill, GradientFill], v; @fill_type = v; end
31
+ def fill_type=(v)
32
+ DataTypeValidator.validate "Fill.fill_type", [PatternFill, GradientFill], v
33
+ @fill_type = v
34
+ end
32
35
  end
33
36
  end
@@ -33,7 +33,7 @@ module Axlsx
33
33
  # The charset of the font
34
34
  # @return [Integer]
35
35
  # @note
36
- # The following values are defined in the OOXML specification and are OS dependant values
36
+ # The following values are defined in the OOXML specification and are OS dependent values
37
37
  # 0 ANSI_CHARSET
38
38
  # 1 DEFAULT_CHARSET
39
39
  # 2 SYMBOL_CHARSET
@@ -112,15 +112,34 @@ module Axlsx
112
112
  attr_reader :sz
113
113
 
114
114
  # @see name
115
- def name=(v) Axlsx.validate_string v; @name = v end
115
+ def name=(v)
116
+ Axlsx.validate_string v
117
+ @name = v
118
+ end
119
+
116
120
  # @see charset
117
- def charset=(v) Axlsx.validate_unsigned_int v; @charset = v end
121
+ def charset=(v)
122
+ Axlsx.validate_unsigned_int v
123
+ @charset = v
124
+ end
125
+
118
126
  # @see family
119
- def family=(v) Axlsx.validate_unsigned_int v; @family = v end
127
+ def family=(v)
128
+ Axlsx.validate_unsigned_int v
129
+ @family = v
130
+ end
131
+
120
132
  # @see b
121
- def b=(v) Axlsx.validate_boolean v; @b = v end
133
+ def b=(v)
134
+ Axlsx.validate_boolean v
135
+ @b = v
136
+ end
137
+
122
138
  # @see i
123
- def i=(v) Axlsx.validate_boolean v; @i = v end
139
+ def i=(v)
140
+ Axlsx.validate_boolean v
141
+ @i = v
142
+ end
124
143
 
125
144
  # @see u
126
145
  def u=(v)
@@ -131,19 +150,46 @@ module Axlsx
131
150
  end
132
151
 
133
152
  # @see strike
134
- def strike=(v) Axlsx.validate_boolean v; @strike = v end
153
+ def strike=(v)
154
+ Axlsx.validate_boolean v
155
+ @strike = v
156
+ end
157
+
135
158
  # @see outline
136
- def outline=(v) Axlsx.validate_boolean v; @outline = v end
159
+ def outline=(v)
160
+ Axlsx.validate_boolean v
161
+ @outline = v
162
+ end
163
+
137
164
  # @see shadow
138
- def shadow=(v) Axlsx.validate_boolean v; @shadow = v end
165
+ def shadow=(v)
166
+ Axlsx.validate_boolean v
167
+ @shadow = v
168
+ end
169
+
139
170
  # @see condense
140
- def condense=(v) Axlsx.validate_boolean v; @condense = v end
171
+ def condense=(v)
172
+ Axlsx.validate_boolean v
173
+ @condense = v
174
+ end
175
+
141
176
  # @see extend
142
- def extend=(v) Axlsx.validate_boolean v; @extend = v end
177
+ def extend=(v)
178
+ Axlsx.validate_boolean v
179
+ @extend = v
180
+ end
181
+
143
182
  # @see color
144
- def color=(v) DataTypeValidator.validate "Font.color", Color, v; @color = v end
183
+ def color=(v)
184
+ DataTypeValidator.validate "Font.color", Color, v
185
+ @color = v
186
+ end
187
+
145
188
  # @see sz
146
- def sz=(v) Axlsx.validate_unsigned_int v; @sz = v end
189
+ def sz=(v)
190
+ Axlsx.validate_unsigned_int v
191
+ @sz = v
192
+ end
147
193
 
148
194
  # Serializes the object
149
195
  # @param [String] str
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
4
- # A GradientFill defines the color and positioning for gradiant cell fill.
4
+ # A GradientFill defines the color and positioning for gradient cell fill.
5
5
  # @see Open Office XML Part 1 §18.8.24
6
6
  class GradientFill
7
7
  include Axlsx::OptionsParser
@@ -55,10 +55,16 @@ module Axlsx
55
55
  attr_reader :stop
56
56
 
57
57
  # @see type
58
- def type=(v) Axlsx.validate_gradient_type v; @type = v end
58
+ def type=(v)
59
+ Axlsx.validate_gradient_type v
60
+ @type = v
61
+ end
59
62
 
60
63
  # @see degree
61
- def degree=(v) Axlsx.validate_float v; @degree = v end
64
+ def degree=(v)
65
+ Axlsx.validate_float v
66
+ @degree = v
67
+ end
62
68
 
63
69
  # @see left
64
70
  def left=(v)
@@ -22,9 +22,16 @@ module Axlsx
22
22
  end
23
23
 
24
24
  # @see color
25
- def color=(v) DataTypeValidator.validate "GradientStop.color", Color, v; @color = v end
25
+ def color=(v)
26
+ DataTypeValidator.validate "GradientStop.color", Color, v
27
+ @color = v
28
+ end
29
+
26
30
  # @see position
27
- def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, ->(arg) { arg >= 0 && arg <= 1 }; @position = v end
31
+ def position=(v)
32
+ DataTypeValidator.validate "GradientStop.position", Float, v, ->(arg) { arg >= 0 && arg <= 1 }
33
+ @position = v
34
+ end
28
35
 
29
36
  # Serializes the object
30
37
  # @param [String] str
@@ -61,10 +61,16 @@ module Axlsx
61
61
  attr_reader :numFmtId
62
62
 
63
63
  # @see numFmtId
64
- def numFmtId=(v) Axlsx.validate_unsigned_int v; @numFmtId = v end
64
+ def numFmtId=(v)
65
+ Axlsx.validate_unsigned_int v
66
+ @numFmtId = v
67
+ end
65
68
 
66
69
  # @see formatCode
67
- def formatCode=(v) Axlsx.validate_string v; @formatCode = v end
70
+ def formatCode=(v)
71
+ Axlsx.validate_string v
72
+ @formatCode = v
73
+ end
68
74
 
69
75
  # Serializes the object
70
76
  # @param [String] str
@@ -49,11 +49,22 @@ module Axlsx
49
49
  attr_reader :patternType
50
50
 
51
51
  # @see fgColor
52
- def fgColor=(v) DataTypeValidator.validate "PatternFill.fgColor", Color, v; @fgColor = v end
52
+ def fgColor=(v)
53
+ DataTypeValidator.validate "PatternFill.fgColor", Color, v
54
+ @fgColor = v
55
+ end
56
+
53
57
  # @see bgColor
54
- def bgColor=(v) DataTypeValidator.validate "PatternFill.bgColor", Color, v; @bgColor = v end
58
+ def bgColor=(v)
59
+ DataTypeValidator.validate "PatternFill.bgColor", Color, v
60
+ @bgColor = v
61
+ end
62
+
55
63
  # @see patternType
56
- def patternType=(v) Axlsx.validate_pattern_type v; @patternType = v end
64
+ def patternType=(v)
65
+ Axlsx.validate_pattern_type v
66
+ @patternType = v
67
+ end
57
68
 
58
69
  # Serializes the object
59
70
  # @param [String] str
@@ -1,27 +1,27 @@
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 'dxf'
19
+ require_relative 'xf'
20
+ require_relative 'cell_protection'
21
21
 
22
22
  # The Styles class manages worksheet styles
23
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.
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
+ # 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
25
  # @see Office Open XML Part 1 18.8.11 for gory details on how this stuff gets put together
26
26
  # @see Styles#add_style
27
27
  # @note The recommended way to manage styles is with add_style
@@ -156,7 +156,7 @@ module Axlsx
156
156
  # ws = p.workbook.add_worksheet
157
157
  #
158
158
  # # 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"}
159
+ # title = ws.styles.add_style(:bg_color => "FFFF0000", :fg_color=>"FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
160
160
  #
161
161
  # ws.add_row ["Least Popular Pets"]
162
162
  # ws.add_row ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
@@ -174,7 +174,7 @@ module Axlsx
174
174
  #
175
175
  # # define your styles
176
176
  # title = ws.styles.add_style(:bg_color => "FFFF0000",
177
- # :fg_color=>"#FF000000",
177
+ # :fg_color=>"FF000000",
178
178
  # :border=>Axlsx::STYLE_THIN_BORDER,
179
179
  # :alignment=>{:horizontal => :center})
180
180
  #
@@ -209,10 +209,10 @@ module Axlsx
209
209
  #
210
210
  # # define your styles
211
211
  # profitable = wb.styles.add_style(:bg_color => "FFFF0000",
212
- # :fg_color=>"#FF000000",
212
+ # :fg_color=>"FF000000",
213
213
  # :type => :dxf)
214
214
  #
215
- # ws.add_row ["Genreated At:", Time.now], :styles=>[nil, date_time]
215
+ # ws.add_row ["Generated At:", Time.now], :styles=>[nil, date_time]
216
216
  # ws.add_row ["Previous Year Quarterly Profits (JPY)"], :style=>title
217
217
  # ws.add_row ["Quarter", "Profit", "% of Total"], :style=>title
218
218
  # ws.add_row ["Q1", 4000, 40], :style=>[title, currency, percent]
@@ -245,7 +245,7 @@ module Axlsx
245
245
 
246
246
  font_defaults = { name: @fonts.first.name, sz: @fonts.first.sz, family: @fonts.first.family }
247
247
 
248
- raw_style = { type: :xf }.merge(font_defaults).merge(options)
248
+ raw_style = { type: :xf }.merge(font_defaults, options)
249
249
 
250
250
  if raw_style[:format_code]
251
251
  raw_style.delete(:num_fmt)
@@ -275,7 +275,7 @@ module Axlsx
275
275
  if options[:type] == :xf
276
276
  xf_index = (cellXfs << style)
277
277
 
278
- # Add styles to style_index cache for re-use
278
+ # Add styles to style_index cache for reuse
279
279
  style_index[xf_index] = raw_style
280
280
 
281
281
  xf_index
@@ -298,7 +298,7 @@ module Axlsx
298
298
 
299
299
  # parses add_style options for alignment
300
300
  # noop if options hash does not include :alignment key
301
- # @option options [Hash] alignment A hash of options to prive the CellAlignment intializer
301
+ # @option options [Hash] alignment A hash of options to prive the CellAlignment initializer
302
302
  # @return [CellAlignment]
303
303
  # @see CellAlignment
304
304
  def parse_alignment_options(options = {})
@@ -325,27 +325,60 @@ module Axlsx
325
325
  def parse_font_options(options = {})
326
326
  return if (options.keys & [:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name]).empty?
327
327
 
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)
328
+ font = Font.new(Axlsx.instance_values_for(fonts.first).merge(options))
333
329
  font.color = Color.new(rgb: options[:fg_color]) if options[:fg_color]
334
330
  font.name = options[:font_name] if options[:font_name]
335
331
  options[:type] == :dxf ? font : fonts << font
336
332
  end
337
333
 
338
334
  # 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
335
+ # @note noop unless at least one of the documented attributes is specified in options
336
+ # @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
337
+ # @option options [String] pattern_type The fill pattern to apply to the fill
338
+ # @option options [String] pattern_bg_color The rgb color to apply to the fill as the first color
339
+ # @option options [String] pattern_fg_color The rgb color to apply to the fill as the second color
341
340
  # @return [Fill|Integer]
342
341
  def parse_fill_options(options = {})
343
- return unless options[:bg_color]
342
+ return unless options[:bg_color] || options[:pattern_type] || options[:pattern_bg_color] || options[:pattern_fg_color]
344
343
 
345
- color = Color.new(rgb: options[:bg_color])
344
+ pattern_type = options[:pattern_type] || :solid
346
345
  dxf = options[:type] == :dxf
347
- color_key = dxf ? :bgColor : :fgColor
348
- pattern = PatternFill.new(:patternType => :solid, color_key => color)
346
+
347
+ pattern_options = {
348
+ patternType: pattern_type
349
+ }
350
+
351
+ if options[:pattern_bg_color] && options[:bg_color]
352
+ 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.'
353
+ end
354
+
355
+ bg_color = options[:pattern_bg_color] || options[:bg_color]
356
+ fg_color = options[:pattern_fg_color]
357
+
358
+ # Both bgColor and fgColor happens to configure the background of the cell.
359
+ # One of them sets the "background" of the cell, while the other one is
360
+ # responsible for the "pattern" of the cell. When you pick "solid" pattern for
361
+ # a normal xf style, then it's a rectangle covering all bgColor with fgColor,
362
+ # which means we need to to set the given background color to fgColor as well.
363
+ # For some reason I wasn't able find, it works the opposite for dxf styles
364
+ # (differential formatting records), so to get the expected color, we need
365
+ # to put it into bgColor. We only need these cross-assignments when using
366
+ # "solid" pattern and the user provided only one color to get the least
367
+ # amount of surprise
368
+
369
+ if bg_color
370
+ pattern_options[:bgColor] = Color.new(rgb: bg_color)
371
+ elsif pattern_type == :solid && fg_color
372
+ pattern_options[:bgColor] = Color.new(rgb: fg_color)
373
+ end
374
+
375
+ if fg_color
376
+ pattern_options[:fgColor] = Color.new(rgb: fg_color)
377
+ elsif pattern_type == :solid && bg_color
378
+ pattern_options[:fgColor] = Color.new(rgb: bg_color)
379
+ end
380
+
381
+ pattern = PatternFill.new(pattern_options)
349
382
  fill = Fill.new(pattern)
350
383
  dxf ? fill : fills << fill
351
384
  end
@@ -364,7 +397,7 @@ module Axlsx
364
397
  # { :border => { :style => :thick, :color => "FFFF0000", :edges => [:top, :bottom] }
365
398
  # @return [Border|Integer]
366
399
  def parse_border_options(options = {})
367
- if options[:border].nil? && Border::EDGES.all? { |x| options["border_#{x}".to_sym].nil? }
400
+ if options[:border].nil? && Border::EDGES.all? { |x| options[:"border_#{x}"].nil? }
368
401
  return nil
369
402
  end
370
403
 
@@ -409,7 +442,7 @@ module Axlsx
409
442
  end
410
443
 
411
444
  Border::EDGES.each do |edge|
412
- val = options["border_#{edge}".to_sym]
445
+ val = options[:"border_#{edge}"]
413
446
 
414
447
  if val
415
448
  borders_array << val.merge(edges: [edge])
@@ -430,8 +463,8 @@ module Axlsx
430
463
  end
431
464
  end
432
465
 
433
- if options["border_#{edge}".to_sym]
434
- edge_b_opts = edge_b_opts.merge(options["border_#{edge}".to_sym])
466
+ if options[:"border_#{edge}"]
467
+ edge_b_opts = edge_b_opts.merge(options[:"border_#{edge}"])
435
468
  skip_edge = false
436
469
  end
437
470
 
@@ -472,7 +505,12 @@ module Axlsx
472
505
  # If this is a standard xf we pull from numFmts the highest current and increment for num_fmt
473
506
  options[:num_fmt] ||= (@numFmts.map(&:numFmtId).max + 1) if options[:type] != :dxf
474
507
  numFmt = NumFmt.new(numFmtId: options[:num_fmt] || 0, formatCode: options[:format_code].to_s)
475
- options[:type] == :dxf ? numFmt : (numFmts << numFmt; numFmt.numFmtId)
508
+ if options[:type] == :dxf
509
+ numFmt
510
+ else
511
+ numFmts << numFmt
512
+ numFmt.numFmtId
513
+ end
476
514
  else
477
515
  options[:num_fmt]
478
516
  end
@@ -534,8 +572,10 @@ module Axlsx
534
572
  @cellXfs << Xf.new(borderId: 0, xfId: 0, numFmtId: 14, fontId: 0, fillId: 0, applyNumberFormat: 1)
535
573
  @cellXfs.lock
536
574
 
537
- @dxfs = SimpleTypedList.new(Dxf, "dxfs"); @dxfs.lock
538
- @tableStyles = TableStyles.new(defaultTableStyle: "TableStyleMedium9", defaultPivotStyle: "PivotStyleLight16"); @tableStyles.lock
575
+ @dxfs = SimpleTypedList.new(Dxf, "dxfs")
576
+ @dxfs.lock
577
+ @tableStyles = TableStyles.new(defaultTableStyle: "TableStyleMedium9", defaultPivotStyle: "PivotStyleLight16")
578
+ @tableStyles.lock
539
579
  end
540
580
  end
541
581
  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