caxlsx 3.4.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/README.md +9 -11
  4. data/Rakefile +7 -5
  5. data/lib/axlsx/content_type/abstract_content_type.rb +9 -4
  6. data/lib/axlsx/content_type/content_type.rb +7 -5
  7. data/lib/axlsx/content_type/default.rb +4 -2
  8. data/lib/axlsx/content_type/override.rb +4 -2
  9. data/lib/axlsx/doc_props/app.rb +26 -24
  10. data/lib/axlsx/doc_props/core.rb +8 -6
  11. data/lib/axlsx/drawing/area_chart.rb +10 -8
  12. data/lib/axlsx/drawing/area_series.rb +12 -10
  13. data/lib/axlsx/drawing/ax_data_source.rb +2 -0
  14. data/lib/axlsx/drawing/axes.rb +6 -4
  15. data/lib/axlsx/drawing/axis.rb +21 -19
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -12
  17. data/lib/axlsx/drawing/bar_chart.rb +13 -11
  18. data/lib/axlsx/drawing/bar_series.rb +8 -6
  19. data/lib/axlsx/drawing/bubble_chart.rb +6 -4
  20. data/lib/axlsx/drawing/bubble_series.rb +8 -6
  21. data/lib/axlsx/drawing/cat_axis.rb +12 -10
  22. data/lib/axlsx/drawing/chart.rb +20 -18
  23. data/lib/axlsx/drawing/d_lbls.rb +7 -5
  24. data/lib/axlsx/drawing/drawing.rb +58 -56
  25. data/lib/axlsx/drawing/graphic_frame.rb +6 -4
  26. data/lib/axlsx/drawing/hyperlink.rb +10 -8
  27. data/lib/axlsx/drawing/line_3D_chart.rb +7 -5
  28. data/lib/axlsx/drawing/line_chart.rb +10 -8
  29. data/lib/axlsx/drawing/line_series.rb +12 -10
  30. data/lib/axlsx/drawing/marker.rb +9 -7
  31. data/lib/axlsx/drawing/num_data.rb +9 -7
  32. data/lib/axlsx/drawing/num_data_source.rb +9 -7
  33. data/lib/axlsx/drawing/num_val.rb +7 -5
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +7 -5
  35. data/lib/axlsx/drawing/pic.rb +16 -14
  36. data/lib/axlsx/drawing/picture_locking.rb +3 -1
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +5 -3
  38. data/lib/axlsx/drawing/pie_series.rb +8 -6
  39. data/lib/axlsx/drawing/scaling.rb +8 -6
  40. data/lib/axlsx/drawing/scatter_chart.rb +7 -5
  41. data/lib/axlsx/drawing/scatter_series.rb +14 -12
  42. data/lib/axlsx/drawing/ser_axis.rb +7 -5
  43. data/lib/axlsx/drawing/series.rb +6 -4
  44. data/lib/axlsx/drawing/series_title.rb +6 -4
  45. data/lib/axlsx/drawing/str_data.rb +7 -5
  46. data/lib/axlsx/drawing/str_val.rb +6 -4
  47. data/lib/axlsx/drawing/title.rb +13 -14
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +4 -2
  49. data/lib/axlsx/drawing/val_axis.rb +4 -2
  50. data/lib/axlsx/drawing/view_3D.rb +9 -7
  51. data/lib/axlsx/drawing/vml_drawing.rb +18 -16
  52. data/lib/axlsx/drawing/vml_shape.rb +24 -22
  53. data/lib/axlsx/package.rb +69 -66
  54. data/lib/axlsx/rels/relationship.rb +10 -5
  55. data/lib/axlsx/rels/relationships.rb +5 -3
  56. data/lib/axlsx/stylesheet/border.rb +6 -4
  57. data/lib/axlsx/stylesheet/border_pr.rb +5 -3
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +12 -10
  59. data/lib/axlsx/stylesheet/cell_protection.rb +5 -3
  60. data/lib/axlsx/stylesheet/cell_style.rb +10 -8
  61. data/lib/axlsx/stylesheet/color.rb +9 -7
  62. data/lib/axlsx/stylesheet/dxf.rb +5 -3
  63. data/lib/axlsx/stylesheet/fill.rb +3 -1
  64. data/lib/axlsx/stylesheet/font.rb +18 -16
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +6 -4
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +6 -4
  67. data/lib/axlsx/stylesheet/num_fmt.rb +8 -10
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +5 -3
  69. data/lib/axlsx/stylesheet/styles.rb +69 -71
  70. data/lib/axlsx/stylesheet/table_style.rb +7 -5
  71. data/lib/axlsx/stylesheet/table_style_element.rb +6 -4
  72. data/lib/axlsx/stylesheet/table_styles.rb +6 -4
  73. data/lib/axlsx/stylesheet/xf.rb +18 -16
  74. data/lib/axlsx/util/accessors.rb +4 -2
  75. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  76. data/lib/axlsx/util/constants.rb +117 -104
  77. data/lib/axlsx/util/mime_type_utils.rb +3 -5
  78. data/lib/axlsx/util/options_parser.rb +3 -1
  79. data/lib/axlsx/util/serialized_attributes.rb +42 -17
  80. data/lib/axlsx/util/simple_typed_list.rb +47 -47
  81. data/lib/axlsx/util/storage.rb +11 -10
  82. data/lib/axlsx/util/validators.rb +101 -41
  83. data/lib/axlsx/util/zip_command.rb +10 -10
  84. data/lib/axlsx/version.rb +3 -1
  85. data/lib/axlsx/workbook/defined_name.rb +6 -4
  86. data/lib/axlsx/workbook/defined_names.rb +3 -1
  87. data/lib/axlsx/workbook/shared_strings_table.rb +8 -6
  88. data/lib/axlsx/workbook/workbook.rb +78 -76
  89. data/lib/axlsx/workbook/workbook_view.rb +3 -1
  90. data/lib/axlsx/workbook/workbook_views.rb +3 -1
  91. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +65 -8
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +7 -3
  93. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +11 -7
  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 +5 -3
  97. data/lib/axlsx/workbook/worksheet/break.rb +3 -1
  98. data/lib/axlsx/workbook/worksheet/cell.rb +53 -54
  99. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +31 -27
  100. data/lib/axlsx/workbook/worksheet/cfvo.rb +5 -3
  101. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -1
  102. data/lib/axlsx/workbook/worksheet/col.rb +5 -3
  103. data/lib/axlsx/workbook/worksheet/col_breaks.rb +5 -3
  104. data/lib/axlsx/workbook/worksheet/color_scale.rb +12 -10
  105. data/lib/axlsx/workbook/worksheet/cols.rb +3 -1
  106. data/lib/axlsx/workbook/worksheet/comment.rb +8 -6
  107. data/lib/axlsx/workbook/worksheet/comments.rb +6 -4
  108. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +9 -4
  109. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +18 -16
  110. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +3 -1
  111. data/lib/axlsx/workbook/worksheet/data_bar.rb +14 -13
  112. data/lib/axlsx/workbook/worksheet/data_validation.rb +30 -28
  113. data/lib/axlsx/workbook/worksheet/data_validations.rb +3 -1
  114. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +7 -5
  115. data/lib/axlsx/workbook/worksheet/dimension.rb +4 -2
  116. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -2
  117. data/lib/axlsx/workbook/worksheet/icon_set.rb +23 -6
  118. data/lib/axlsx/workbook/worksheet/merged_cells.rb +5 -5
  119. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -2
  120. data/lib/axlsx/workbook/worksheet/page_margins.rb +15 -10
  121. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -2
  122. data/lib/axlsx/workbook/worksheet/page_setup.rb +11 -9
  123. data/lib/axlsx/workbook/worksheet/pane.rb +11 -9
  124. data/lib/axlsx/workbook/worksheet/pivot_table.rb +20 -19
  125. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -6
  126. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +2 -0
  127. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -1
  128. data/lib/axlsx/workbook/worksheet/protected_range.rb +3 -1
  129. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -3
  130. data/lib/axlsx/workbook/worksheet/rich_text.rb +3 -1
  131. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +16 -14
  132. data/lib/axlsx/workbook/worksheet/row.rb +6 -7
  133. data/lib/axlsx/workbook/worksheet/row_breaks.rb +6 -4
  134. data/lib/axlsx/workbook/worksheet/selection.rb +9 -7
  135. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -2
  136. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  137. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +6 -2
  138. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +8 -4
  139. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +10 -8
  140. data/lib/axlsx/workbook/worksheet/sheet_view.rb +15 -13
  141. data/lib/axlsx/workbook/worksheet/table.rb +9 -7
  142. data/lib/axlsx/workbook/worksheet/table_style_info.rb +4 -2
  143. data/lib/axlsx/workbook/worksheet/tables.rb +3 -1
  144. data/lib/axlsx/workbook/worksheet/worksheet.rb +38 -37
  145. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -2
  146. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +8 -2
  147. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +6 -4
  148. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +4 -2
  149. data/lib/axlsx.rb +56 -42
  150. data/lib/caxlsx.rb +3 -1
  151. metadata +49 -43
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The Font class details a font instance for use in styling cells.
3
5
  # @note The recommended way to manage fonts, and other styles is Styles#add_style
@@ -110,46 +112,46 @@ module Axlsx
110
112
  attr_reader :sz
111
113
 
112
114
  # @see name
113
- def name=(v) Axlsx::validate_string v; @name = v end
115
+ def name=(v) Axlsx.validate_string v; @name = v end
114
116
  # @see charset
115
- def charset=(v) Axlsx::validate_unsigned_int v; @charset = v end
117
+ def charset=(v) Axlsx.validate_unsigned_int v; @charset = v end
116
118
  # @see family
117
- def family=(v) Axlsx::validate_unsigned_int v; @family = v end
119
+ def family=(v) Axlsx.validate_unsigned_int v; @family = v end
118
120
  # @see b
119
- def b=(v) Axlsx::validate_boolean v; @b = v end
121
+ def b=(v) Axlsx.validate_boolean v; @b = v end
120
122
  # @see i
121
- def i=(v) Axlsx::validate_boolean v; @i = v end
123
+ def i=(v) Axlsx.validate_boolean v; @i = v end
122
124
 
123
125
  # @see u
124
126
  def u=(v)
125
- v = :single if (v == true || v == 1 || v == :true || v == 'true')
126
- v = :none if (v == false || v == 0 || v == :false || v == 'false')
127
- Axlsx::validate_cell_u v
127
+ v = :single if v == true || v == 1 || v == :true || v == 'true'
128
+ v = :none if v == false || v == 0 || v == :false || v == 'false'
129
+ Axlsx.validate_cell_u v
128
130
  @u = v
129
131
  end
130
132
 
131
133
  # @see strike
132
- def strike=(v) Axlsx::validate_boolean v; @strike = v end
134
+ def strike=(v) Axlsx.validate_boolean v; @strike = v end
133
135
  # @see outline
134
- def outline=(v) Axlsx::validate_boolean v; @outline = v end
136
+ def outline=(v) Axlsx.validate_boolean v; @outline = v end
135
137
  # @see shadow
136
- def shadow=(v) Axlsx::validate_boolean v; @shadow = v end
138
+ def shadow=(v) Axlsx.validate_boolean v; @shadow = v end
137
139
  # @see condense
138
- def condense=(v) Axlsx::validate_boolean v; @condense = v end
140
+ def condense=(v) Axlsx.validate_boolean v; @condense = v end
139
141
  # @see extend
140
- def extend=(v) Axlsx::validate_boolean v; @extend = v end
142
+ def extend=(v) Axlsx.validate_boolean v; @extend = v end
141
143
  # @see color
142
144
  def color=(v) DataTypeValidator.validate "Font.color", Color, v; @color = v end
143
145
  # @see sz
144
- def sz=(v) Axlsx::validate_unsigned_int v; @sz = v end
146
+ def sz=(v) Axlsx.validate_unsigned_int v; @sz = v end
145
147
 
146
148
  # Serializes the object
147
149
  # @param [String] str
148
150
  # @return [String]
149
- def to_xml_string(str = '')
151
+ def to_xml_string(str = +'')
150
152
  str << '<font>'
151
153
  Axlsx.instance_values_for(self).each do |k, v|
152
- v.is_a?(Color) ? v.to_xml_string(str) : (str << ('<' << k.to_s << ' val="' << Axlsx.booleanize(v).to_s << '"/>'))
154
+ v.is_a?(Color) ? v.to_xml_string(str) : (str << '<' << k.to_s << ' val="' << Axlsx.booleanize(v).to_s << '"/>')
153
155
  end
154
156
  str << '</font>'
155
157
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A GradientFill defines the color and positioning for gradiant cell fill.
3
5
  # @see Open Office XML Part 1 §18.8.24
@@ -53,10 +55,10 @@ module Axlsx
53
55
  attr_reader :stop
54
56
 
55
57
  # @see type
56
- def type=(v) Axlsx::validate_gradient_type v; @type = v end
58
+ def type=(v) Axlsx.validate_gradient_type v; @type = v end
57
59
 
58
60
  # @see degree
59
- def degree=(v) Axlsx::validate_float v; @degree = v end
61
+ def degree=(v) Axlsx.validate_float v; @degree = v end
60
62
 
61
63
  # @see left
62
64
  def left=(v)
@@ -84,13 +86,13 @@ module Axlsx
84
86
 
85
87
  # validates that the value provided is between 0.0 and 1.0
86
88
  def validate_format_percentage(name, value)
87
- DataTypeValidator.validate name, Float, value, lambda { |arg| arg >= 0.0 && arg <= 1.0 }
89
+ DataTypeValidator.validate name, Float, value, ->(arg) { arg >= 0.0 && arg <= 1.0 }
88
90
  end
89
91
 
90
92
  # Serializes the object
91
93
  # @param [String] str
92
94
  # @return [String]
93
- def to_xml_string(str = '')
95
+ def to_xml_string(str = +'')
94
96
  str << '<gradientFill '
95
97
  serialized_attributes str
96
98
  str << '>'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The GradientStop object represents a color point in a gradient.
3
5
  # @see Open Office XML Part 1 §18.8.24
@@ -22,14 +24,14 @@ module Axlsx
22
24
  # @see color
23
25
  def color=(v) DataTypeValidator.validate "GradientStop.color", Color, v; @color = v end
24
26
  # @see position
25
- def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, lambda { |arg| arg >= 0 && arg <= 1 }; @position = v end
27
+ def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, ->(arg) { arg >= 0 && arg <= 1 }; @position = v end
26
28
 
27
29
  # Serializes the object
28
30
  # @param [String] str
29
31
  # @return [String]
30
- def to_xml_string(str = '')
31
- str << ('<stop position="' << position.to_s << '">')
32
- self.color.to_xml_string(str)
32
+ def to_xml_string(str = +'')
33
+ str << '<stop position="' << position.to_s << '">'
34
+ color.to_xml_string(str)
33
35
  str << '</stop>'
34
36
  end
35
37
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A NumFmt object defines an identifier and formatting code for data in cells.
3
5
  # @note The recommended way to manage styles is Styles#add_style
@@ -18,7 +20,7 @@ module Axlsx
18
20
  serializable_attributes :formatCode, :numFmtId
19
21
 
20
22
  # @return [String] The formatting to use for this number format.
21
- # @see http://support.microsoft.com/kb/264372
23
+ # @see https://support.microsoft.com/kb/264372
22
24
  attr_reader :formatCode
23
25
 
24
26
  # @return [Integer] An unsigned integer referencing a standard or custom number format.
@@ -59,25 +61,21 @@ module Axlsx
59
61
  attr_reader :numFmtId
60
62
 
61
63
  # @see numFmtId
62
- def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
64
+ def numFmtId=(v) Axlsx.validate_unsigned_int v; @numFmtId = v end
63
65
 
64
66
  # @see formatCode
65
- def formatCode=(v) Axlsx::validate_string v; @formatCode = v end
67
+ def formatCode=(v) Axlsx.validate_string v; @formatCode = v end
66
68
 
67
69
  # Serializes the object
68
70
  # @param [String] str
69
71
  # @return [String]
70
- def to_xml_string(str = '')
72
+ def to_xml_string(str = +'')
71
73
  serialized_tag('numFmt', str)
72
74
  end
73
75
 
74
76
  # Override to avoid removing underscores
75
- def serialized_attributes(str = '', additional_attributes = {})
76
- attributes = declared_attributes.merge! additional_attributes
77
- attributes.each do |key, value|
78
- str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.booleanize(value)}\" "
79
- end
80
- str
77
+ def serialized_attributes(str = +'', additional_attributes = {})
78
+ super(str, additional_attributes, false)
81
79
  end
82
80
  end
83
81
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A PatternFill is the pattern and solid fill styling for a cell.
3
5
  # @note The recommended way to manage styles is with Styles#add_style
@@ -51,13 +53,13 @@ module Axlsx
51
53
  # @see bgColor
52
54
  def bgColor=(v) DataTypeValidator.validate "PatternFill.bgColor", Color, v; @bgColor = v end
53
55
  # @see patternType
54
- def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end
56
+ def patternType=(v) Axlsx.validate_pattern_type v; @patternType = v end
55
57
 
56
58
  # Serializes the object
57
59
  # @param [String] str
58
60
  # @return [String]
59
- def to_xml_string(str = '')
60
- str << ('<patternFill patternType="' << patternType.to_s << '">')
61
+ def to_xml_string(str = +'')
62
+ str << '<patternFill patternType="' << patternType.to_s << '">'
61
63
  if fgColor.is_a?(Color)
62
64
  fgColor.to_xml_string str, "fgColor"
63
65
  end
@@ -1,21 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
- require 'axlsx/stylesheet/border.rb'
3
- require 'axlsx/stylesheet/border_pr.rb'
4
- require 'axlsx/stylesheet/cell_alignment.rb'
5
- require 'axlsx/stylesheet/cell_style.rb'
6
- require 'axlsx/stylesheet/color.rb'
7
- require 'axlsx/stylesheet/fill.rb'
8
- require 'axlsx/stylesheet/font.rb'
9
- require 'axlsx/stylesheet/gradient_fill.rb'
10
- require 'axlsx/stylesheet/gradient_stop.rb'
11
- require 'axlsx/stylesheet/num_fmt.rb'
12
- require 'axlsx/stylesheet/pattern_fill.rb'
13
- require 'axlsx/stylesheet/table_style.rb'
14
- require 'axlsx/stylesheet/table_styles.rb'
15
- require 'axlsx/stylesheet/table_style_element.rb'
16
- require 'axlsx/stylesheet/dxf.rb'
17
- require 'axlsx/stylesheet/xf.rb'
18
- require 'axlsx/stylesheet/cell_protection.rb'
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'
19
21
 
20
22
  # The Styles class manages worksheet styles
21
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.
@@ -108,14 +110,14 @@ module Axlsx
108
110
  # @see Styles#add_style
109
111
  attr_reader :dxfs
110
112
 
111
- # 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
112
114
  # @return [SimpleTypedList]
113
115
  # @note The recommended way to manage styles is with add_style
114
116
  # @see Styles#add_style
115
117
  attr_reader :tableStyles
116
118
 
117
119
  # Creates a new Styles object and prepopulates it with the requires objects to generate a valid package style part.
118
- def initialize()
120
+ def initialize
119
121
  load_default_styles
120
122
  end
121
123
 
@@ -263,12 +265,12 @@ module Axlsx
263
265
  alignment = parse_alignment_options options
264
266
  protection = parse_protection_options options
265
267
 
266
- case options[:type]
267
- when :dxf
268
- style = Dxf.new :fill => fill, :font => font, :numFmt => numFmt, :border => border, :alignment => alignment, :protection => protection
269
- else
270
- 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?
271
- 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
272
274
 
273
275
  if options[:type] == :xf
274
276
  xf_index = (cellXfs << style)
@@ -276,11 +278,9 @@ module Axlsx
276
278
  # Add styles to style_index cache for re-use
277
279
  style_index[xf_index] = raw_style
278
280
 
279
- return xf_index
281
+ xf_index
280
282
  else
281
- dxf_index = (dxfs << style)
282
-
283
- return dxf_index
283
+ dxfs << style
284
284
  end
285
285
  end
286
286
 
@@ -327,10 +327,10 @@ module Axlsx
327
327
 
328
328
  Axlsx.instance_values_for(fonts.first).each do |key, value|
329
329
  # Thanks for that 1.8.7 - cant do a simple merge...
330
- options[key.to_sym] = value unless options.keys.include?(key.to_sym)
330
+ options[key.to_sym] = value unless options.key?(key.to_sym)
331
331
  end
332
332
  font = Font.new(options)
333
- 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]
334
334
  font.name = options[:font_name] if options[:font_name]
335
335
  options[:type] == :dxf ? font : fonts << font
336
336
  end
@@ -342,7 +342,7 @@ module Axlsx
342
342
  def parse_fill_options(options = {})
343
343
  return unless options[:bg_color]
344
344
 
345
- color = Color.new(:rgb => options[:bg_color])
345
+ color = Color.new(rgb: options[:bg_color])
346
346
  dxf = options[:type] == :dxf
347
347
  color_key = dxf ? :bgColor : :fgColor
348
348
  pattern = PatternFill.new(:patternType => :solid, color_key => color)
@@ -370,7 +370,7 @@ module Axlsx
370
370
 
371
371
  if options[:border].is_a?(Integer)
372
372
  if options[:border] >= borders.size
373
- raise ArgumentError, (ERR_INVALID_BORDER_ID % options[:border])
373
+ raise ArgumentError, format(ERR_INVALID_BORDER_ID, options[:border])
374
374
  end
375
375
 
376
376
  if options[:type] == :dxf
@@ -380,9 +380,9 @@ module Axlsx
380
380
  end
381
381
  end
382
382
 
383
- validate_border_hash = ->(val) {
384
- if !(val.keys.include?(:style) && val.keys.include?(:color))
385
- 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])
386
386
  end
387
387
  }
388
388
 
@@ -390,24 +390,22 @@ module Axlsx
390
390
 
391
391
  if options[:border].nil?
392
392
  base_border_opts = {}
393
- else
394
- if options[:border].is_a?(Array)
395
- borders_array += options[:border]
393
+ elsif options[:border].is_a?(Array)
394
+ borders_array += options[:border]
396
395
 
397
- base_border_opts = {}
396
+ base_border_opts = {}
398
397
 
399
- options[:border].each do |b_opts|
400
- if b_opts[:edges].nil?
401
- base_border_opts = base_border_opts.merge(b_opts)
402
- end
398
+ options[:border].each do |b_opts|
399
+ if b_opts[:edges].nil?
400
+ base_border_opts = base_border_opts.merge(b_opts)
403
401
  end
404
- else
405
- borders_array << options[:border]
402
+ end
403
+ else
404
+ borders_array << options[:border]
406
405
 
407
- base_border_opts = options[:border]
406
+ base_border_opts = options[:border]
408
407
 
409
- validate_border_hash.call(base_border_opts)
410
- end
408
+ validate_border_hash.call(base_border_opts)
411
409
  end
412
410
 
413
411
  Border::EDGES.each do |edge|
@@ -441,23 +439,23 @@ module Axlsx
441
439
  next
442
440
  end
443
441
 
444
- if !edge_b_opts.empty?
442
+ unless edge_b_opts.empty?
445
443
  if base_border_opts.empty?
446
444
  validate_border_hash.call(edge_b_opts)
447
445
  end
448
446
 
449
447
  border.prs << BorderPr.new({
450
- :name => edge,
451
- :style => edge_b_opts[:style],
452
- :color => Color.new(:rgb => edge_b_opts[:color])
448
+ name: edge,
449
+ style: edge_b_opts[:style],
450
+ color: Color.new(rgb: edge_b_opts[:color])
453
451
  })
454
452
  end
455
453
  end
456
454
 
457
455
  if options[:type] == :dxf
458
- return border
456
+ border
459
457
  else
460
- return borders << border
458
+ borders << border
461
459
  end
462
460
  end
463
461
 
@@ -472,8 +470,8 @@ module Axlsx
472
470
  # When the type is :dxf we always need to create a new numFmt object
473
471
  if options[:format_code] || options[:type] == :dxf
474
472
  # If this is a standard xf we pull from numFmts the highest current and increment for num_fmt
475
- options[:num_fmt] ||= (@numFmts.map { |num_fmt| num_fmt.numFmtId }.max + 1) if options[:type] != :dxf
476
- numFmt = NumFmt.new(:numFmtId => options[:num_fmt] || 0, :formatCode => options[:format_code].to_s)
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)
477
475
  options[:type] == :dxf ? numFmt : (numFmts << numFmt; numFmt.numFmtId)
478
476
  else
479
477
  options[:num_fmt]
@@ -483,8 +481,8 @@ module Axlsx
483
481
  # Serializes the object
484
482
  # @param [String] str
485
483
  # @return [String]
486
- def to_xml_string(str = '')
487
- str << ('<styleSheet xmlns="' << XML_NS << '">')
484
+ def to_xml_string(str = +'')
485
+ str << '<styleSheet xmlns="' << XML_NS << '">'
488
486
  instance_vals = Axlsx.instance_values_for(self)
489
487
  [:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
490
488
  instance_vals[key.to_s].to_xml_string(str) unless instance_vals[key.to_s].nil?
@@ -498,46 +496,46 @@ module Axlsx
498
496
  # Axlsx::STYLE_THIN_BORDER
499
497
  def load_default_styles
500
498
  @numFmts = SimpleTypedList.new NumFmt, 'numFmts'
501
- @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDD, :formatCode => "yyyy/mm/dd")
502
- @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")
503
501
 
504
502
  @numFmts.lock
505
503
 
506
504
  @fonts = SimpleTypedList.new Font, 'fonts'
507
- @fonts << Font.new(:name => "Arial", :sz => 11, :family => 1)
505
+ @fonts << Font.new(name: "Arial", sz: 11, family: 1)
508
506
  @fonts.lock
509
507
 
510
508
  @fills = SimpleTypedList.new Fill, 'fills'
511
- @fills << Fill.new(Axlsx::PatternFill.new(:patternType => :none))
512
- @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))
513
511
  @fills.lock
514
512
 
515
513
  @borders = SimpleTypedList.new Border, 'borders'
516
514
  @borders << Border.new
517
515
  black_border = Border.new
518
516
  [:left, :right, :top, :bottom].each do |item|
519
- 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"))
520
518
  end
521
519
  @borders << black_border
522
520
  @borders.lock
523
521
 
524
522
  @cellStyleXfs = SimpleTypedList.new Xf, "cellStyleXfs"
525
- @cellStyleXfs << Xf.new(:borderId => 0, :numFmtId => 0, :fontId => 0, :fillId => 0)
523
+ @cellStyleXfs << Xf.new(borderId: 0, numFmtId: 0, fontId: 0, fillId: 0)
526
524
  @cellStyleXfs.lock
527
525
 
528
526
  @cellStyles = SimpleTypedList.new CellStyle, 'cellStyles'
529
- @cellStyles << CellStyle.new(:name => "Normal", :builtinId => 0, :xfId => 0)
527
+ @cellStyles << CellStyle.new(name: "Normal", builtinId: 0, xfId: 0)
530
528
  @cellStyles.lock
531
529
 
532
530
  @cellXfs = SimpleTypedList.new Xf, "cellXfs"
533
- @cellXfs << Xf.new(:borderId => 0, :xfId => 0, :numFmtId => 0, :fontId => 0, :fillId => 0)
534
- @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)
535
533
  # default date formatting
536
- @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)
537
535
  @cellXfs.lock
538
536
 
539
537
  @dxfs = SimpleTypedList.new(Dxf, "dxfs"); @dxfs.lock
540
- @tableStyles = TableStyles.new(:defaultTableStyle => "TableStyleMedium9", :defaultPivotStyle => "PivotStyleLight16"); @tableStyles.lock
538
+ @tableStyles = TableStyles.new(defaultTableStyle: "TableStyleMedium9", defaultPivotStyle: "PivotStyleLight16"); @tableStyles.lock
541
539
  end
542
540
  end
543
541
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A single table style definition and is a collection for tableStyleElements
3
5
  # @note Table are not supported in this version and only the defaults required for a valid workbook are created.
@@ -31,18 +33,18 @@ module Axlsx
31
33
  attr_reader :table
32
34
 
33
35
  # @see name
34
- def name=(v) Axlsx::validate_string v; @name = v end
36
+ def name=(v) Axlsx.validate_string v; @name = v end
35
37
  # @see pivot
36
- def pivot=(v) Axlsx::validate_boolean v; @pivot = v end
38
+ def pivot=(v) Axlsx.validate_boolean v; @pivot = v end
37
39
  # @see table
38
- def table=(v) Axlsx::validate_boolean v; @table = v end
40
+ def table=(v) Axlsx.validate_boolean v; @table = v end
39
41
 
40
42
  # Serializes the object
41
43
  # @param [String] str
42
44
  # @return [String]
43
- def to_xml_string(str = '')
45
+ def to_xml_string(str = +'')
44
46
  str << '<tableStyle '
45
- serialized_attributes str, { :count => self.size }
47
+ serialized_attributes str, { count: size }
46
48
  str << '>'
47
49
  each { |table_style_el| table_style_el.to_xml_string(str) }
48
50
  str << '</tableStyle>'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # an element of style that belongs to a table style.
3
5
  # @note tables and table styles are not supported in this version. This class exists in preparation for that support.
@@ -56,18 +58,18 @@ module Axlsx
56
58
  attr_reader :dxfId
57
59
 
58
60
  # @see type
59
- 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
60
62
 
61
63
  # @see size
62
- def size=(v) Axlsx::validate_unsigned_int v; @size = v end
64
+ def size=(v) Axlsx.validate_unsigned_int v; @size = v end
63
65
 
64
66
  # @see dxfId
65
- def dxfId=(v) Axlsx::validate_unsigned_int v; @dxfId = v end
67
+ def dxfId=(v) Axlsx.validate_unsigned_int v; @dxfId = v end
66
68
 
67
69
  # Serializes the object
68
70
  # @param [String] str
69
71
  # @return [String]
70
- def to_xml_string(str = '')
72
+ def to_xml_string(str = +'')
71
73
  serialized_tag('tableStyleElement', str)
72
74
  end
73
75
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # TableStyles represents a collection of style definitions for table styles and pivot table styles.
3
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.
@@ -24,16 +26,16 @@ module Axlsx
24
26
  attr_reader :defaultPivotStyle
25
27
 
26
28
  # @see defaultTableStyle
27
- def defaultTableStyle=(v) Axlsx::validate_string(v); @defaultTableStyle = v; end
29
+ def defaultTableStyle=(v) Axlsx.validate_string(v); @defaultTableStyle = v; end
28
30
  # @see defaultPivotStyle
29
- def defaultPivotStyle=(v) Axlsx::validate_string(v); @defaultPivotStyle = v; end
31
+ def defaultPivotStyle=(v) Axlsx.validate_string(v); @defaultPivotStyle = v; end
30
32
 
31
33
  # Serializes the object
32
34
  # @param [String] str
33
35
  # @return [String]
34
- def to_xml_string(str = '')
36
+ def to_xml_string(str = +'')
35
37
  str << '<tableStyles '
36
- serialized_attributes str, { :count => self.size }
38
+ serialized_attributes str, { count: size }
37
39
  str << '>'
38
40
  each { |table_style| table_style.to_xml_string(str) }
39
41
  str << '</tableStyles>'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
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
3
5
  # @see Styles#add_style
@@ -99,45 +101,45 @@ module Axlsx
99
101
  def protection=(v) DataTypeValidator.validate "Xf.protection", CellProtection, v; @protection = v end
100
102
 
101
103
  # @see numFmtId
102
- def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
104
+ def numFmtId=(v) Axlsx.validate_unsigned_int v; @numFmtId = v end
103
105
 
104
106
  # @see fontId
105
- def fontId=(v) Axlsx::validate_unsigned_int v; @fontId = v end
107
+ def fontId=(v) Axlsx.validate_unsigned_int v; @fontId = v end
106
108
  # @see fillId
107
- def fillId=(v) Axlsx::validate_unsigned_int v; @fillId = v end
109
+ def fillId=(v) Axlsx.validate_unsigned_int v; @fillId = v end
108
110
  # @see borderId
109
- def borderId=(v) Axlsx::validate_unsigned_int v; @borderId = v end
111
+ def borderId=(v) Axlsx.validate_unsigned_int v; @borderId = v end
110
112
  # @see xfId
111
- def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
113
+ def xfId=(v) Axlsx.validate_unsigned_int v; @xfId = v end
112
114
  # @see quotePrefix
113
- def quotePrefix=(v) Axlsx::validate_boolean v; @quotePrefix = v end
115
+ def quotePrefix=(v) Axlsx.validate_boolean v; @quotePrefix = v end
114
116
  # @see pivotButton
115
- def pivotButton=(v) Axlsx::validate_boolean v; @pivotButton = v end
117
+ def pivotButton=(v) Axlsx.validate_boolean v; @pivotButton = v end
116
118
  # @see applyNumberFormat
117
- def applyNumberFormat=(v) Axlsx::validate_boolean v; @applyNumberFormat = v end
119
+ def applyNumberFormat=(v) Axlsx.validate_boolean v; @applyNumberFormat = v end
118
120
  # @see applyFont
119
- def applyFont=(v) Axlsx::validate_boolean v; @applyFont = v end
121
+ def applyFont=(v) Axlsx.validate_boolean v; @applyFont = v end
120
122
  # @see applyFill
121
- def applyFill=(v) Axlsx::validate_boolean v; @applyFill = v end
123
+ def applyFill=(v) Axlsx.validate_boolean v; @applyFill = v end
122
124
 
123
125
  # @see applyBorder
124
- def applyBorder=(v) Axlsx::validate_boolean v; @applyBorder = v end
126
+ def applyBorder=(v) Axlsx.validate_boolean v; @applyBorder = v end
125
127
 
126
128
  # @see applyAlignment
127
- def applyAlignment=(v) Axlsx::validate_boolean v; @applyAlignment = v end
129
+ def applyAlignment=(v) Axlsx.validate_boolean v; @applyAlignment = v end
128
130
 
129
131
  # @see applyProtection
130
- def applyProtection=(v) Axlsx::validate_boolean v; @applyProtection = v end
132
+ def applyProtection=(v) Axlsx.validate_boolean v; @applyProtection = v end
131
133
 
132
134
  # Serializes the object
133
135
  # @param [String] str
134
136
  # @return [String]
135
- def to_xml_string(str = '')
137
+ def to_xml_string(str = +'')
136
138
  str << '<xf '
137
139
  serialized_attributes str
138
140
  str << '>'
139
- alignment.to_xml_string(str) if self.alignment
140
- protection.to_xml_string(str) if self.protection
141
+ alignment.to_xml_string(str) if alignment
142
+ protection.to_xml_string(str) if protection
141
143
  str << '</xf>'
142
144
  end
143
145
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # This module defines some of the more common validating attribute
3
5
  # accessors that we use in Axlsx
@@ -43,7 +45,7 @@ module Axlsx
43
45
  end
44
46
 
45
47
  # Template for defining validated write accessors
46
- SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end".freeze
48
+ SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end"
47
49
 
48
50
  # Creates the reader and writer access methods
49
51
  # @param [Array] symbols The names of the attributes to create
@@ -54,7 +56,7 @@ module Axlsx
54
56
  symbols.each do |symbol|
55
57
  attr_reader symbol
56
58
 
57
- module_eval(SETTER % [symbol, validator, symbol], __FILE__, __LINE__)
59
+ module_eval(format(SETTER, symbol, validator, symbol), __FILE__, __LINE__)
58
60
  end
59
61
  end
60
62
  end