caxlsx 3.3.0 → 3.4.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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +24 -5
  4. data/Rakefile +0 -1
  5. data/lib/axlsx/content_type/abstract_content_type.rb +2 -5
  6. data/lib/axlsx/content_type/content_type.rb +0 -4
  7. data/lib/axlsx/content_type/default.rb +1 -5
  8. data/lib/axlsx/content_type/override.rb +0 -4
  9. data/lib/axlsx/doc_props/app.rb +1 -6
  10. data/lib/axlsx/doc_props/core.rb +1 -6
  11. data/lib/axlsx/drawing/area_chart.rb +3 -6
  12. data/lib/axlsx/drawing/area_series.rb +1 -4
  13. data/lib/axlsx/drawing/ax_data_source.rb +1 -6
  14. data/lib/axlsx/drawing/axes.rb +5 -6
  15. data/lib/axlsx/drawing/axis.rb +7 -12
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +7 -10
  17. data/lib/axlsx/drawing/bar_chart.rb +6 -9
  18. data/lib/axlsx/drawing/bar_series.rb +2 -8
  19. data/lib/axlsx/drawing/bubble_chart.rb +2 -5
  20. data/lib/axlsx/drawing/bubble_series.rb +3 -6
  21. data/lib/axlsx/drawing/cat_axis.rb +2 -7
  22. data/lib/axlsx/drawing/chart.rb +7 -12
  23. data/lib/axlsx/drawing/d_lbls.rb +23 -22
  24. data/lib/axlsx/drawing/drawing.rb +4 -8
  25. data/lib/axlsx/drawing/graphic_frame.rb +0 -3
  26. data/lib/axlsx/drawing/hyperlink.rb +4 -7
  27. data/lib/axlsx/drawing/line_3D_chart.rb +10 -14
  28. data/lib/axlsx/drawing/line_chart.rb +3 -6
  29. data/lib/axlsx/drawing/line_series.rb +1 -4
  30. data/lib/axlsx/drawing/marker.rb +5 -9
  31. data/lib/axlsx/drawing/num_data.rb +4 -9
  32. data/lib/axlsx/drawing/num_data_source.rb +3 -7
  33. data/lib/axlsx/drawing/num_val.rb +2 -5
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +4 -6
  35. data/lib/axlsx/drawing/pic.rb +46 -13
  36. data/lib/axlsx/drawing/picture_locking.rb +3 -6
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -7
  38. data/lib/axlsx/drawing/pie_series.rb +1 -6
  39. data/lib/axlsx/drawing/scaling.rb +2 -5
  40. data/lib/axlsx/drawing/scatter_chart.rb +2 -5
  41. data/lib/axlsx/drawing/scatter_series.rb +2 -5
  42. data/lib/axlsx/drawing/ser_axis.rb +2 -6
  43. data/lib/axlsx/drawing/series.rb +3 -5
  44. data/lib/axlsx/drawing/series_title.rb +0 -2
  45. data/lib/axlsx/drawing/str_data.rb +3 -8
  46. data/lib/axlsx/drawing/str_val.rb +2 -5
  47. data/lib/axlsx/drawing/title.rb +12 -15
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +5 -7
  49. data/lib/axlsx/drawing/val_axis.rb +1 -4
  50. data/lib/axlsx/drawing/view_3D.rb +24 -24
  51. data/lib/axlsx/drawing/vml_drawing.rb +2 -5
  52. data/lib/axlsx/drawing/vml_shape.rb +4 -7
  53. data/lib/axlsx/package.rb +35 -36
  54. data/lib/axlsx/rels/relationship.rb +21 -24
  55. data/lib/axlsx/rels/relationships.rb +3 -6
  56. data/lib/axlsx/stylesheet/border.rb +1 -4
  57. data/lib/axlsx/stylesheet/border_pr.rb +3 -5
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +2 -10
  59. data/lib/axlsx/stylesheet/cell_protection.rb +1 -4
  60. data/lib/axlsx/stylesheet/cell_style.rb +3 -7
  61. data/lib/axlsx/stylesheet/color.rb +6 -5
  62. data/lib/axlsx/stylesheet/dxf.rb +2 -6
  63. data/lib/axlsx/stylesheet/fill.rb +0 -4
  64. data/lib/axlsx/stylesheet/font.rb +7 -6
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +4 -6
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +2 -3
  67. data/lib/axlsx/stylesheet/num_fmt.rb +1 -4
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +3 -5
  69. data/lib/axlsx/stylesheet/styles.rb +53 -45
  70. data/lib/axlsx/stylesheet/table_style.rb +5 -8
  71. data/lib/axlsx/stylesheet/table_style_element.rb +1 -4
  72. data/lib/axlsx/stylesheet/table_styles.rb +3 -7
  73. data/lib/axlsx/stylesheet/xf.rb +3 -6
  74. data/lib/axlsx/util/accessors.rb +2 -4
  75. data/lib/axlsx/util/constants.rb +3 -5
  76. data/lib/axlsx/util/mime_type_utils.rb +13 -0
  77. data/lib/axlsx/util/options_parser.rb +1 -2
  78. data/lib/axlsx/util/serialized_attributes.rb +4 -5
  79. data/lib/axlsx/util/simple_typed_list.rb +18 -17
  80. data/lib/axlsx/util/storage.rb +32 -36
  81. data/lib/axlsx/util/validators.rb +7 -4
  82. data/lib/axlsx/util/zip_command.rb +0 -2
  83. data/lib/axlsx/version.rb +1 -2
  84. data/lib/axlsx/workbook/defined_name.rb +6 -5
  85. data/lib/axlsx/workbook/defined_names.rb +1 -2
  86. data/lib/axlsx/workbook/shared_strings_table.rb +3 -6
  87. data/lib/axlsx/workbook/workbook.rb +96 -91
  88. data/lib/axlsx/workbook/workbook_view.rb +5 -10
  89. data/lib/axlsx/workbook/workbook_views.rb +1 -3
  90. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +9 -8
  91. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +6 -6
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +13 -14
  93. data/lib/axlsx/workbook/worksheet/border_creator.rb +29 -26
  94. data/lib/axlsx/workbook/worksheet/break.rb +2 -5
  95. data/lib/axlsx/workbook/worksheet/cell.rb +46 -26
  96. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +11 -11
  97. data/lib/axlsx/workbook/worksheet/cfvo.rb +2 -2
  98. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -5
  99. data/lib/axlsx/workbook/worksheet/col.rb +4 -7
  100. data/lib/axlsx/workbook/worksheet/col_breaks.rb +4 -5
  101. data/lib/axlsx/workbook/worksheet/color_scale.rb +10 -12
  102. data/lib/axlsx/workbook/worksheet/cols.rb +6 -6
  103. data/lib/axlsx/workbook/worksheet/comment.rb +4 -5
  104. data/lib/axlsx/workbook/worksheet/comments.rb +6 -10
  105. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +4 -5
  106. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +2 -6
  107. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +2 -4
  108. data/lib/axlsx/workbook/worksheet/data_bar.rb +20 -22
  109. data/lib/axlsx/workbook/worksheet/data_validation.rb +4 -5
  110. data/lib/axlsx/workbook/worksheet/data_validations.rb +2 -5
  111. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -3
  112. data/lib/axlsx/workbook/worksheet/dimension.rb +5 -4
  113. data/lib/axlsx/workbook/worksheet/header_footer.rb +0 -1
  114. data/lib/axlsx/workbook/worksheet/icon_set.rb +2 -3
  115. data/lib/axlsx/workbook/worksheet/merged_cells.rb +8 -8
  116. data/lib/axlsx/workbook/worksheet/outline_pr.rb +0 -1
  117. data/lib/axlsx/workbook/worksheet/page_margins.rb +2 -2
  118. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -3
  119. data/lib/axlsx/workbook/worksheet/page_setup.rb +117 -120
  120. data/lib/axlsx/workbook/worksheet/pane.rb +16 -17
  121. data/lib/axlsx/workbook/worksheet/pivot_table.rb +8 -11
  122. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -11
  123. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -4
  124. data/lib/axlsx/workbook/worksheet/print_options.rb +0 -1
  125. data/lib/axlsx/workbook/worksheet/protected_range.rb +4 -5
  126. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +9 -9
  127. data/lib/axlsx/workbook/worksheet/rich_text.rb +4 -6
  128. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +21 -5
  129. data/lib/axlsx/workbook/worksheet/row.rb +24 -15
  130. data/lib/axlsx/workbook/worksheet/row_breaks.rb +3 -4
  131. data/lib/axlsx/workbook/worksheet/selection.rb +7 -9
  132. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +5 -6
  133. data/lib/axlsx/workbook/worksheet/sheet_data.rb +4 -6
  134. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +18 -18
  135. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +4 -4
  136. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +12 -13
  137. data/lib/axlsx/workbook/worksheet/sheet_view.rb +35 -42
  138. data/lib/axlsx/workbook/worksheet/table.rb +7 -9
  139. data/lib/axlsx/workbook/worksheet/table_style_info.rb +2 -3
  140. data/lib/axlsx/workbook/worksheet/tables.rb +4 -4
  141. data/lib/axlsx/workbook/worksheet/worksheet.rb +63 -35
  142. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -6
  143. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +3 -2
  144. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +5 -6
  145. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +4 -4
  146. data/lib/axlsx.rb +23 -9
  147. data/lib/caxlsx.rb +0 -1
  148. metadata +3 -3
@@ -1,39 +1,43 @@
1
- # encoding: UTF-8
2
-
3
1
  module Axlsx
4
2
  class BorderCreator
5
- attr_reader :worksheet, :cells, :edges, :width, :color
6
-
7
- def initialize(worksheet, cells, args)
3
+ def initialize(worksheet:, cells:, edges: nil, style: nil, color: nil)
8
4
  @worksheet = worksheet
9
- @cells = cells
10
- if args.is_a?(Hash)
11
- @edges = args[:edges] || Axlsx::Border::EDGES
12
- @width = args[:style] || :thin
13
- @color = args[:color] || '000000'
14
- else
15
- @edges = args || Axlsx::Border::Edges
16
- @width = :thin
17
- @color = '000000'
18
- end
5
+ @cells = cells
6
+
7
+ @edges = edges || :all
8
+ @style = style || :thin
9
+ @color = color || "000000"
19
10
 
20
11
  if @edges == :all
21
12
  @edges = Axlsx::Border::EDGES
22
- elsif @edges.is_a?(Array)
23
- @edges = (@edges.map(&:to_sym).uniq & Axlsx::Border::EDGES)
13
+ elsif !@edges.is_a?(Array)
14
+ raise ArgumentError.new("Invalid edges provided, #{@edges}")
24
15
  else
25
- @edges = []
16
+ @edges = @edges.map { |x| x&.to_sym }.uniq
17
+
18
+ if !(@edges - Axlsx::Border::EDGES).empty?
19
+ raise ArgumentError.new("Invalid edges provided, #{edges}")
20
+ end
26
21
  end
27
22
  end
28
23
 
29
24
  def draw
30
- @edges.each do |edge|
31
- worksheet.add_style(
32
- border_cells[edge],
25
+ if @cells.size == 1
26
+ @worksheet.add_style(
27
+ first_cell,
33
28
  {
34
- border: {style: @width, color: @color, edges: [edge]}
29
+ border: { style: @style, color: @color, edges: @edges }
35
30
  }
36
31
  )
32
+ else
33
+ @edges.each do |edge|
34
+ @worksheet.add_style(
35
+ border_cells[edge],
36
+ {
37
+ border: { style: @style, color: @color, edges: [edge] }
38
+ }
39
+ )
40
+ end
37
41
  end
38
42
  end
39
43
 
@@ -44,16 +48,16 @@ module Axlsx
44
48
  top: "#{first_cell}:#{last_col}#{first_row}",
45
49
  right: "#{last_col}#{first_row}:#{last_cell}",
46
50
  bottom: "#{first_col}#{last_row}:#{last_cell}",
47
- left: "#{first_cell}:#{first_col}#{last_row}",
51
+ left: "#{first_cell}:#{first_col}#{last_row}"
48
52
  }
49
53
  end
50
54
 
51
55
  def first_cell
52
- @first_cell ||= cells.first.r
56
+ @first_cell ||= @cells.first.r
53
57
  end
54
58
 
55
59
  def last_cell
56
- @last_cell ||= cells.last.r
60
+ @last_cell ||= @cells.last.r
57
61
  end
58
62
 
59
63
  def first_row
@@ -71,6 +75,5 @@ module Axlsx
71
75
  def last_col
72
76
  @last_col ||= last_cell.scan(/\D+/).first
73
77
  end
74
-
75
78
  end
76
79
  end
@@ -1,9 +1,7 @@
1
1
  module Axlsx
2
-
3
2
  # The Break class stores the details for row and column page breaks.
4
3
  # @see RowBreaks, ColBreaks
5
4
  class Break
6
-
7
5
  include Axlsx::OptionsParser
8
6
  include Axlsx::Accessors
9
7
  include Axlsx::SerializedAttributes
@@ -15,7 +13,7 @@ module Axlsx
15
13
  # @option options [Integer] max Zero-based index of end row or column of the break. For row breaks, specifies column index; for column breaks, specifies row index.
16
14
  # @option options [Boolean] man Manual Break flag. 1 means the break is a manually inserted break.
17
15
  # @option option [Boolean] pt Flag indicating that a PivotTable created this break.
18
- def initialize(options={})
16
+ def initialize(options = {})
19
17
  parse_options options
20
18
  yield self if block_given?
21
19
  end
@@ -27,9 +25,8 @@ module Axlsx
27
25
  serializable_attributes :id, :min, :max, :man, :pt
28
26
 
29
27
  # serializes the break to xml
30
- def to_xml_string(str='')
28
+ def to_xml_string(str = '')
31
29
  serialized_tag('brk', str)
32
30
  end
33
31
  end
34
32
  end
35
-
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'cgi'
3
2
  module Axlsx
4
3
  # A cell in a worksheet.
@@ -7,7 +6,6 @@ module Axlsx
7
6
  #
8
7
  # @see Worksheet#add_row
9
8
  class Cell
10
-
11
9
  include Axlsx::OptionsParser
12
10
 
13
11
  # @param [Row] row The row this cell belongs to.
@@ -30,10 +28,9 @@ module Axlsx
30
28
  # @option options [String] color an 8 letter rgb specification
31
29
  # @option options [Number] formula_value The value to cache for a formula cell.
32
30
  # @option options [Symbol] scheme must be one of :none, major, :minor
33
- # @option options [Boolean] escape_formulas - Whether to treat a value starting with an equal
34
- # sign as formula (default) or as simple string.
35
- # Allowing user generated data to be interpreted as formulas can be dangerous
36
- # (see https://www.owasp.org/index.php/CSV_Injection for details).
31
+ # @option options [Boolean] escape_formulas Whether to treat values starting with an equals
32
+ # sign as formulas or as literal strings. Allowing user-generated data to be interpreted as
33
+ # formulas is a security risk. See https://www.owasp.org/index.php/CSV_Injection for details.
37
34
  def initialize(row, value = nil, options = {})
38
35
  @row = row
39
36
  # Do not use instance vars if not needed to use less RAM
@@ -42,15 +39,13 @@ module Axlsx
42
39
  type = options.delete(:type) || cell_type_from_value(value)
43
40
  self.type = type unless type == :string
44
41
 
45
- escape_formulas = options[:escape_formulas]
46
- self.escape_formulas = escape_formulas unless escape_formulas.nil?
47
-
48
42
  val = options.delete(:style)
49
43
  self.style = val unless val.nil? || val == 0
50
44
  val = options.delete(:formula_value)
51
45
  self.formula_value = val unless val.nil?
52
46
 
53
47
  parse_options(options)
48
+ self.escape_formulas = row.worksheet.escape_formulas if escape_formulas.nil?
54
49
 
55
50
  self.value = value
56
51
  value.cell = self if contains_rich_text?
@@ -75,6 +70,10 @@ module Axlsx
75
70
  CELL_TYPES = [:date, :time, :float, :integer, :richtext,
76
71
  :string, :boolean, :iso_8601, :text].freeze
77
72
 
73
+ # Leading characters that indicate a formula.
74
+ # See: https://owasp.org/www-community/attacks/CSV_Injection
75
+ FORMULA_PREFIXES = ['-', '=', '+', '@', '%', '|', "\r", "\t"].freeze
76
+
78
77
  # The index of the cellXfs item to be applied to this cell.
79
78
  # @return [Integer]
80
79
  # @see Axlsx::Styles
@@ -104,7 +103,7 @@ module Axlsx
104
103
  self.raw_style = new_style
105
104
 
106
105
  wb = row.worksheet.workbook
107
-
106
+
108
107
  wb.styled_cells << self
109
108
  end
110
109
 
@@ -134,16 +133,17 @@ module Axlsx
134
133
  self.value = @value unless !defined?(@value) || @value.nil?
135
134
  end
136
135
 
137
- # Whether to treat a value starting with an equal
138
- # sign as formula (default) or as simple string.
139
- # Allowing user generated data to be interpreted as formulas can be dangerous
140
- # (see https://www.owasp.org/index.php/CSV_Injection for details).
136
+ # Whether to treat values starting with an equals sign as formulas or as literal strings.
137
+ # Allowing user-generated data to be interpreted as formulas is a security risk.
138
+ # See https://www.owasp.org/index.php/CSV_Injection for details.
141
139
  # @return [Boolean]
142
140
  attr_reader :escape_formulas
143
141
 
144
- def escape_formulas=(v)
145
- Axlsx.validate_boolean(v)
146
- @escape_formulas = v
142
+ # Sets whether to treat values starting with an equals sign as formulas or as literal strings.
143
+ # @param [Boolean] value The value to set.
144
+ def escape_formulas=(value)
145
+ Axlsx.validate_boolean(value)
146
+ @escape_formulas = value
147
147
  end
148
148
 
149
149
  # The value of this cell.
@@ -152,7 +152,7 @@ module Axlsx
152
152
 
153
153
  # @see value
154
154
  def value=(v)
155
- #TODO: consider doing value based type determination first?
155
+ # TODO: consider doing value based type determination first?
156
156
  @value = cast_value(v)
157
157
  end
158
158
 
@@ -172,12 +172,14 @@ module Axlsx
172
172
  !is_text_run? && # No inline styles
173
173
  !@value.nil? && # Not nil
174
174
  !@value.empty? && # Not empty
175
- !@value.start_with?(?=) # Not a formula
175
+ !is_formula? && # Not a formula
176
+ !is_array_formula? # Not an array formula
176
177
  end
177
178
 
178
179
  # The inline font_name property for the cell
179
180
  # @return [String]
180
181
  attr_reader :font_name
182
+
181
183
  # @see font_name
182
184
  def font_name=(v) set_run_style :validate_string, :font_name, v; end
183
185
 
@@ -204,6 +206,7 @@ module Axlsx
204
206
  # 255  OEM_CHARSET
205
207
  # @return [String]
206
208
  attr_reader :charset
209
+
207
210
  # @see charset
208
211
  def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end
209
212
 
@@ -215,6 +218,7 @@ module Axlsx
215
218
  # 4 Script
216
219
  # 5 Decorative
217
220
  attr_reader :family
221
+
218
222
  # @see family
219
223
  def family=(v)
220
224
  set_run_style :validate_family, :family, v.to_i
@@ -223,42 +227,49 @@ module Axlsx
223
227
  # The inline bold property for the cell
224
228
  # @return [Boolean]
225
229
  attr_reader :b
230
+
226
231
  # @see b
227
232
  def b=(v) set_run_style :validate_boolean, :b, v; end
228
233
 
229
234
  # The inline italic property for the cell
230
235
  # @return [Boolean]
231
236
  attr_reader :i
237
+
232
238
  # @see i
233
239
  def i=(v) set_run_style :validate_boolean, :i, v; end
234
240
 
235
241
  # The inline strike property for the cell
236
242
  # @return [Boolean]
237
243
  attr_reader :strike
244
+
238
245
  # @see strike
239
246
  def strike=(v) set_run_style :validate_boolean, :strike, v; end
240
247
 
241
248
  # The inline outline property for the cell
242
249
  # @return [Boolean]
243
250
  attr_reader :outline
251
+
244
252
  # @see outline
245
253
  def outline=(v) set_run_style :validate_boolean, :outline, v; end
246
254
 
247
255
  # The inline shadow property for the cell
248
256
  # @return [Boolean]
249
257
  attr_reader :shadow
258
+
250
259
  # @see shadow
251
260
  def shadow=(v) set_run_style :validate_boolean, :shadow, v; end
252
261
 
253
262
  # The inline condense property for the cell
254
263
  # @return [Boolean]
255
264
  attr_reader :condense
265
+
256
266
  # @see condense
257
267
  def condense=(v) set_run_style :validate_boolean, :condense, v; end
258
268
 
259
269
  # The inline extend property for the cell
260
270
  # @return [Boolean]
261
271
  attr_reader :extend
272
+
262
273
  # @see extend
263
274
  def extend=(v) set_run_style :validate_boolean, :extend, v; end
264
275
 
@@ -268,6 +279,7 @@ module Axlsx
268
279
  # @return [String]
269
280
  # @note true is for backwards compatability and is reassigned to :single
270
281
  attr_reader :u
282
+
271
283
  # @see u
272
284
  def u=(v)
273
285
  v = :single if (v == true || v == 1 || v == :true || v == 'true')
@@ -277,15 +289,17 @@ module Axlsx
277
289
  # The inline color property for the cell
278
290
  # @return [Color]
279
291
  attr_reader :color
292
+
280
293
  # @param [String] v The 8 character representation for an rgb color #FFFFFFFF"
281
294
  def color=(v)
282
- @color = v.is_a?(Color) ? v : Color.new(:rgb=>v)
295
+ @color = v.is_a?(Color) ? v : Color.new(:rgb => v)
283
296
  @is_text_run = true
284
297
  end
285
298
 
286
299
  # The inline sz property for the cell
287
300
  # @return [Inteter]
288
301
  attr_reader :sz
302
+
289
303
  # @see sz
290
304
  def sz=(v) set_run_style :validate_unsigned_int, :sz, v; end
291
305
 
@@ -293,6 +307,7 @@ module Axlsx
293
307
  # this must be one of [:baseline, :subscript, :superscript]
294
308
  # @return [Symbol]
295
309
  attr_reader :vertAlign
310
+
296
311
  # @see vertAlign
297
312
  def vertAlign=(v)
298
313
  RestrictionValidator.validate :cell_vertAlign, [:baseline, :subscript, :superscript], v
@@ -303,6 +318,7 @@ module Axlsx
303
318
  # this must be one of [:none, major, minor]
304
319
  # @return [Symbol]
305
320
  attr_reader :scheme
321
+
306
322
  # @see scheme
307
323
  def scheme=(v)
308
324
  RestrictionValidator.validate :cell_scheme, [:none, :major, :minor], v
@@ -329,7 +345,7 @@ module Axlsx
329
345
  # @example Absolute Cell Reference
330
346
  # ws.rows.first.cells.first.r #=> "$A$1"
331
347
  def r_abs
332
- "$#{r.match(%r{([A-Z]+)([0-9]+)})[1,2].join('$')}"
348
+ "$#{r.match(%r{([A-Z]+)([0-9]+)})[1, 2].join('$')}"
333
349
  end
334
350
 
335
351
  # @return [Integer] The cellXfs item index applied to this cell.
@@ -338,6 +354,7 @@ module Axlsx
338
354
  Axlsx::validate_unsigned_int(v)
339
355
  count = styles.cellXfs.size
340
356
  raise ArgumentError, "Invalid cellXfs id" unless v < count
357
+
341
358
  @style = v
342
359
  end
343
360
 
@@ -352,7 +369,7 @@ module Axlsx
352
369
  def merge(target)
353
370
  start, stop = if target.is_a?(String)
354
371
  [self.r, target]
355
- elsif(target.is_a?(Cell))
372
+ elsif target.is_a?(Cell)
356
373
  Axlsx.sort_cells([self, target]).map { |c| c.r }
357
374
  end
358
375
  self.row.worksheet.merge_cells "#{start}:#{stop}" unless stop.nil?
@@ -370,10 +387,12 @@ module Axlsx
370
387
  def is_formula?
371
388
  return false if escape_formulas
372
389
 
373
- type == :string && @value.to_s.start_with?(?=)
390
+ type == :string && @value.to_s.start_with?(*FORMULA_PREFIXES)
374
391
  end
375
392
 
376
393
  def is_array_formula?
394
+ return false if escape_formulas
395
+
377
396
  type == :string && @value.to_s.start_with?('{=') && @value.to_s.end_with?('}')
378
397
  end
379
398
 
@@ -382,7 +401,7 @@ module Axlsx
382
401
  # @param [Boolean] absolute -when false a relative reference will be
383
402
  # returned.
384
403
  # @return [String]
385
- def reference(absolute=true)
404
+ def reference(absolute = true)
386
405
  absolute ? r_abs : r
387
406
  end
388
407
 
@@ -452,6 +471,7 @@ module Axlsx
452
471
  # Utility method for setting inline style attributes
453
472
  def set_run_style(validator, attr, value)
454
473
  return unless INLINE_STYLES.include?(attr.to_sym)
474
+
455
475
  Axlsx.send(validator, value) unless validator.nil?
456
476
  self.instance_variable_set :"@#{attr.to_s}", value
457
477
  @is_text_run = true
@@ -499,6 +519,7 @@ module Axlsx
499
519
  # @see Axlsx#date1904
500
520
  def cast_value(v)
501
521
  return v if v.is_a?(RichText) || v.nil?
522
+
502
523
  case type
503
524
  when :date
504
525
  self.style = STYLE_DATE if self.style == 0
@@ -521,12 +542,11 @@ module Axlsx
521
542
  when :boolean
522
543
  v ? 1 : 0
523
544
  when :iso_8601
524
- #consumer is responsible for ensuring the iso_8601 format when specifying this type
545
+ # consumer is responsible for ensuring the iso_8601 format when specifying this type
525
546
  v
526
547
  else
527
548
  v.to_s
528
549
  end
529
550
  end
530
-
531
551
  end
532
552
  end
@@ -1,5 +1,4 @@
1
1
  module Axlsx
2
-
3
2
  # The Cell Serializer class contains the logic for serializing cells based on their type.
4
3
  class CellSerializer
5
4
  class << self
@@ -8,9 +7,10 @@ module Axlsx
8
7
  # @param [Integer] column_index The index of the cell's column
9
8
  # @param [String] str The string to apend serialization to.
10
9
  # @return [String]
11
- def to_xml_string(row_index, column_index, cell, str='')
10
+ def to_xml_string(row_index, column_index, cell, str = '')
12
11
  str << ('<c r="' << Axlsx::cell_r(column_index, row_index) << '" s="' << cell.style.to_s << '" ')
13
12
  return str << '/>' if cell.value.nil?
13
+
14
14
  method = cell.type
15
15
  self.send(method, cell, str)
16
16
  str << '</c>'
@@ -22,7 +22,7 @@ module Axlsx
22
22
  def run_xml_string(cell, str = '')
23
23
  if cell.is_text_run?
24
24
  valid = RichTextRun::INLINE_STYLES - [:value, :type]
25
- data = Hash[Axlsx.instance_values_for(cell).map{ |k, v| [k.to_sym, v] }]
25
+ data = Hash[Axlsx.instance_values_for(cell).map { |k, v| [k.to_sym, v] }]
26
26
  data = data.select { |key, value| valid.include?(key) && !value.nil? }
27
27
  RichText.new(cell.value.to_s, data).to_xml_string(str)
28
28
  elsif cell.contains_rich_text?
@@ -37,7 +37,7 @@ module Axlsx
37
37
  # @param [Cell] cell The cell that is being serialized
38
38
  # @param [String] str The string the serialized content will be appended to.
39
39
  # @return [String]
40
- def iso_8601(cell, str='')
40
+ def iso_8601(cell, str = '')
41
41
  value_serialization 'd', cell.value, str
42
42
  end
43
43
 
@@ -45,7 +45,7 @@ module Axlsx
45
45
  # @param [Cell] cell The cell that is being serialized
46
46
  # @param [String] str The string the serialized content will be appended to.
47
47
  # @return [String]
48
- def date(cell, str='')
48
+ def date(cell, str = '')
49
49
  value_serialization false, DateTimeConverter::date_to_serial(cell.value).to_s, str
50
50
  end
51
51
 
@@ -53,7 +53,7 @@ module Axlsx
53
53
  # @param [Cell] cell The cell that is being serialized
54
54
  # @param [String] str The string the serialized content will be appended to.
55
55
  # @return [String]
56
- def time(cell, str='')
56
+ def time(cell, str = '')
57
57
  value_serialization false, DateTimeConverter::time_to_serial(cell.value).to_s, str
58
58
  end
59
59
 
@@ -61,7 +61,7 @@ module Axlsx
61
61
  # @param [Cell] cell The cell that is being serialized
62
62
  # @param [String] str The string the serialized content will be appended to.
63
63
  # @return [String]
64
- def boolean(cell, str='')
64
+ def boolean(cell, str = '')
65
65
  value_serialization 'b', cell.value.to_s, str
66
66
  end
67
67
 
@@ -69,7 +69,7 @@ module Axlsx
69
69
  # @param [Cell] cell The cell that is being serialized
70
70
  # @param [String] str The string the serialized content will be appended to.
71
71
  # @return [String]
72
- def float(cell, str='')
72
+ def float(cell, str = '')
73
73
  numeric cell, str
74
74
  end
75
75
 
@@ -85,7 +85,7 @@ module Axlsx
85
85
  # @param [Cell] cell The cell that is being serialized
86
86
  # @param [String] str The string the serialized content will be appended to.
87
87
  # @return [String]
88
- def formula_serialization(cell, str='')
88
+ def formula_serialization(cell, str = '')
89
89
  str << ('t="str"><f>' << cell.clean_value.to_s.sub('=', '') << '</f>')
90
90
  str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil?
91
91
  end
@@ -94,7 +94,7 @@ module Axlsx
94
94
  # @param [Cell] cell The cell that is being serialized
95
95
  # @param [String] str The string the serialized content will be appended to.
96
96
  # @return [String]
97
- def array_formula_serialization(cell, str='')
97
+ def array_formula_serialization(cell, str = '')
98
98
  str << ('t="str">' << '<f t="array" ref="' << cell.r << '">' << cell.clean_value.to_s.sub('{=', '').sub(/}$/, '') << '</f>')
99
99
  str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil?
100
100
  end
@@ -113,7 +113,7 @@ module Axlsx
113
113
  # @param [Cell] cell The cell that is being serialized
114
114
  # @param [String] str The string the serialized content will be appended to.
115
115
  # @return [String]
116
- def string(cell, str='')
116
+ def string(cell, str = '')
117
117
  if cell.is_array_formula?
118
118
  array_formula_serialization cell, str
119
119
  elsif cell.is_formula?
@@ -7,7 +7,6 @@ module Axlsx
7
7
  # @see ConditionalFormattingRule#initialize
8
8
  #
9
9
  class Cfvo
10
-
11
10
  include Axlsx::OptionsParser
12
11
  include Axlsx::SerializedAttributes
13
12
 
@@ -15,7 +14,7 @@ module Axlsx
15
14
  # @option options [Symbol] type The type of conditional formatting value object
16
15
  # @option options [Boolean] gte threshold value usage indicator
17
16
  # @option options [String] val The value of the conditional formatting object
18
- def initialize(options={})
17
+ def initialize(options = {})
19
18
  @gte = true
20
19
  parse_options options
21
20
  end
@@ -47,6 +46,7 @@ module Axlsx
47
46
  # @see val
48
47
  def val=(v)
49
48
  raise ArgumentError, "#{v.inspect} must respond to to_s" unless v.respond_to?(:to_s)
49
+
50
50
  @val = v.to_s
51
51
  end
52
52
 
@@ -1,9 +1,7 @@
1
1
  module Axlsx
2
-
3
- #A collection of Cfvo objects that initializes with the required
4
- #first two items
2
+ # A collection of Cfvo objects that initializes with the required
3
+ # first two items
5
4
  class Cfvos < SimpleTypedList
6
-
7
5
  def initialize
8
6
  super(Cfvo)
9
7
  end
@@ -11,7 +9,7 @@ module Axlsx
11
9
  # Serialize the Cfvo object
12
10
  # @param [String] str
13
11
  # @return [String]
14
- def to_xml_string(str='')
12
+ def to_xml_string(str = '')
15
13
  each { |cfvo| cfvo.to_xml_string(str) }
16
14
  end
17
15
  end
@@ -1,9 +1,6 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
-
4
2
  # The Col class defines column attributes for columns in sheets.
5
3
  class Col
6
-
7
4
  # Maximum column width limit in MS Excel is 255 characters
8
5
  # https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
9
6
  MAX_WIDTH = 255
@@ -19,7 +16,7 @@ module Axlsx
19
16
  # @option options [Boolean] phonetic see Col#phonetic
20
17
  # @option options [Integer] style see Col#style
21
18
  # @option options [Numeric] width see Col#width
22
- def initialize(min, max, options={})
19
+ def initialize(min, max, options = {})
23
20
  Axlsx.validate_unsigned_int(max)
24
21
  Axlsx.validate_unsigned_int(min)
25
22
  @min = min
@@ -90,6 +87,7 @@ module Axlsx
90
87
  def outline_level=(v)
91
88
  Axlsx.validate_unsigned_numeric(v)
92
89
  raise ArgumentError, 'outlineLevel must be between 0 and 7' unless 0 <= v && v <= 7
90
+
93
91
  @outline_level = v
94
92
  end
95
93
  alias :outlineLevel= :outline_level=
@@ -106,14 +104,14 @@ module Axlsx
106
104
  @style = v
107
105
  end
108
106
 
109
- # @see Col#width
107
+ # @see Col#width
110
108
  def width=(v)
111
109
  # Removing this validation make a 10% difference in performance
112
110
  # as it is called EVERY TIME A CELL IS ADDED - the proper solution
113
111
  # is to only set this if a calculated value is greated than the
114
112
  # current @width value.
115
113
  # TODO!!!
116
- #Axlsx.validate_unsigned_numeric(v) unless v == nil
114
+ # Axlsx.validate_unsigned_numeric(v) unless v == nil
117
115
  @custom_width = @best_fit = v != nil
118
116
  @width = v.nil? ? v : [v, MAX_WIDTH].min
119
117
  end
@@ -140,6 +138,5 @@ module Axlsx
140
138
  def to_xml_string(str = '')
141
139
  serialized_tag('col', str)
142
140
  end
143
-
144
141
  end
145
142
  end
@@ -1,10 +1,8 @@
1
1
  module Axlsx
2
-
3
2
  # A collection of Brake objects.
4
- # Please do not use this class directly. Instead use
3
+ # Please do not use this class directly. Instead use
5
4
  # Worksheet#add_break
6
5
  class ColBreaks < SimpleTypedList
7
-
8
6
  # Instantiates a new list restricted to Break types
9
7
  def initialize
10
8
  super Break
@@ -12,7 +10,7 @@ module Axlsx
12
10
 
13
11
  # A column break specific helper for adding a break.
14
12
  # @param [Hash] options A list of options to pass into the Break object
15
- # The max and man options are fixed, however any other valid option for
13
+ # The max and man options are fixed, however any other valid option for
16
14
  # Break will be passed to the created break object.
17
15
  # @see Break
18
16
  def add_break(options)
@@ -25,8 +23,9 @@ module Axlsx
25
23
  # <colBreaks count="1" manualBreakCount="1">
26
24
  # <brk id="3" max="1048575" man="1"/>
27
25
  # </colBreaks>
28
- def to_xml_string(str='')
26
+ def to_xml_string(str = '')
29
27
  return if empty?
28
+
30
29
  str << ('<colBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">')
31
30
  each { |brk| brk.to_xml_string(str) }
32
31
  str << '</colBreaks>'