caxlsx 3.3.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +25 -7
  4. data/Rakefile +7 -6
  5. data/lib/axlsx/content_type/abstract_content_type.rb +11 -9
  6. data/lib/axlsx/content_type/content_type.rb +7 -9
  7. data/lib/axlsx/content_type/default.rb +4 -6
  8. data/lib/axlsx/content_type/override.rb +3 -5
  9. data/lib/axlsx/doc_props/app.rb +27 -30
  10. data/lib/axlsx/doc_props/core.rb +9 -12
  11. data/lib/axlsx/drawing/area_chart.rb +13 -14
  12. data/lib/axlsx/drawing/area_series.rb +13 -14
  13. data/lib/axlsx/drawing/ax_data_source.rb +3 -6
  14. data/lib/axlsx/drawing/axes.rb +10 -9
  15. data/lib/axlsx/drawing/axis.rb +27 -30
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +17 -18
  17. data/lib/axlsx/drawing/bar_chart.rb +16 -17
  18. data/lib/axlsx/drawing/bar_series.rb +9 -13
  19. data/lib/axlsx/drawing/bubble_chart.rb +8 -9
  20. data/lib/axlsx/drawing/bubble_series.rb +9 -10
  21. data/lib/axlsx/drawing/cat_axis.rb +14 -17
  22. data/lib/axlsx/drawing/chart.rb +25 -28
  23. data/lib/axlsx/drawing/d_lbls.rb +29 -26
  24. data/lib/axlsx/drawing/drawing.rb +60 -62
  25. data/lib/axlsx/drawing/graphic_frame.rb +6 -7
  26. data/lib/axlsx/drawing/hyperlink.rb +12 -13
  27. data/lib/axlsx/drawing/line_3D_chart.rb +13 -15
  28. data/lib/axlsx/drawing/line_chart.rb +13 -14
  29. data/lib/axlsx/drawing/line_series.rb +13 -14
  30. data/lib/axlsx/drawing/marker.rb +14 -16
  31. data/lib/axlsx/drawing/num_data.rb +13 -16
  32. data/lib/axlsx/drawing/num_data_source.rb +11 -13
  33. data/lib/axlsx/drawing/num_val.rb +9 -10
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +10 -10
  35. data/lib/axlsx/drawing/pic.rb +57 -22
  36. data/lib/axlsx/drawing/picture_locking.rb +6 -7
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +6 -9
  38. data/lib/axlsx/drawing/pie_series.rb +9 -12
  39. data/lib/axlsx/drawing/scaling.rb +9 -10
  40. data/lib/axlsx/drawing/scatter_chart.rb +9 -10
  41. data/lib/axlsx/drawing/scatter_series.rb +15 -16
  42. data/lib/axlsx/drawing/ser_axis.rb +9 -11
  43. data/lib/axlsx/drawing/series.rb +8 -8
  44. data/lib/axlsx/drawing/series_title.rb +6 -6
  45. data/lib/axlsx/drawing/str_data.rb +10 -13
  46. data/lib/axlsx/drawing/str_val.rb +8 -9
  47. data/lib/axlsx/drawing/title.rb +23 -27
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +8 -8
  49. data/lib/axlsx/drawing/val_axis.rb +5 -6
  50. data/lib/axlsx/drawing/view_3D.rb +32 -30
  51. data/lib/axlsx/drawing/vml_drawing.rb +19 -20
  52. data/lib/axlsx/drawing/vml_shape.rb +25 -26
  53. data/lib/axlsx/package.rb +81 -79
  54. data/lib/axlsx/rels/relationship.rb +30 -28
  55. data/lib/axlsx/rels/relationships.rb +7 -8
  56. data/lib/axlsx/stylesheet/border.rb +7 -8
  57. data/lib/axlsx/stylesheet/border_pr.rb +8 -8
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +14 -20
  59. data/lib/axlsx/stylesheet/cell_protection.rb +6 -7
  60. data/lib/axlsx/stylesheet/cell_style.rb +12 -14
  61. data/lib/axlsx/stylesheet/color.rb +15 -12
  62. data/lib/axlsx/stylesheet/dxf.rb +7 -9
  63. data/lib/axlsx/stylesheet/fill.rb +3 -5
  64. data/lib/axlsx/stylesheet/font.rb +24 -21
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +9 -9
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +7 -6
  67. data/lib/axlsx/stylesheet/num_fmt.rb +9 -14
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +8 -8
  69. data/lib/axlsx/stylesheet/styles.rb +104 -98
  70. data/lib/axlsx/stylesheet/table_style.rb +8 -9
  71. data/lib/axlsx/stylesheet/table_style_element.rb +7 -8
  72. data/lib/axlsx/stylesheet/table_styles.rb +8 -10
  73. data/lib/axlsx/stylesheet/xf.rb +21 -22
  74. data/lib/axlsx/util/accessors.rb +6 -6
  75. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  76. data/lib/axlsx/util/constants.rb +119 -108
  77. data/lib/axlsx/util/mime_type_utils.rb +11 -0
  78. data/lib/axlsx/util/options_parser.rb +4 -3
  79. data/lib/axlsx/util/serialized_attributes.rb +45 -21
  80. data/lib/axlsx/util/simple_typed_list.rb +58 -57
  81. data/lib/axlsx/util/storage.rb +38 -41
  82. data/lib/axlsx/util/validators.rb +107 -44
  83. data/lib/axlsx/util/zip_command.rb +10 -12
  84. data/lib/axlsx/version.rb +3 -2
  85. data/lib/axlsx/workbook/defined_name.rb +11 -8
  86. data/lib/axlsx/workbook/defined_names.rb +4 -3
  87. data/lib/axlsx/workbook/shared_strings_table.rb +10 -11
  88. data/lib/axlsx/workbook/workbook.rb +121 -114
  89. data/lib/axlsx/workbook/workbook_view.rb +8 -11
  90. data/lib/axlsx/workbook/workbook_views.rb +4 -4
  91. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +72 -14
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -7
  93. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +24 -21
  94. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  95. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
  96. data/lib/axlsx/workbook/worksheet/border_creator.rb +30 -25
  97. data/lib/axlsx/workbook/worksheet/break.rb +4 -5
  98. data/lib/axlsx/workbook/worksheet/cell.rb +92 -65
  99. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +32 -28
  100. data/lib/axlsx/workbook/worksheet/cfvo.rb +7 -5
  101. data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
  102. data/lib/axlsx/workbook/worksheet/col.rb +9 -10
  103. data/lib/axlsx/workbook/worksheet/col_breaks.rb +8 -7
  104. data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
  105. data/lib/axlsx/workbook/worksheet/cols.rb +9 -7
  106. data/lib/axlsx/workbook/worksheet/comment.rb +12 -11
  107. data/lib/axlsx/workbook/worksheet/comments.rb +10 -12
  108. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +12 -8
  109. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +19 -21
  110. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +5 -5
  111. data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
  112. data/lib/axlsx/workbook/worksheet/data_validation.rb +34 -33
  113. data/lib/axlsx/workbook/worksheet/data_validations.rb +5 -6
  114. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
  115. data/lib/axlsx/workbook/worksheet/dimension.rb +9 -6
  116. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -3
  117. data/lib/axlsx/workbook/worksheet/icon_set.rb +24 -8
  118. data/lib/axlsx/workbook/worksheet/merged_cells.rb +10 -10
  119. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -3
  120. data/lib/axlsx/workbook/worksheet/page_margins.rb +17 -12
  121. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -4
  122. data/lib/axlsx/workbook/worksheet/page_setup.rb +128 -129
  123. data/lib/axlsx/workbook/worksheet/pane.rb +27 -26
  124. data/lib/axlsx/workbook/worksheet/pivot_table.rb +23 -25
  125. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
  126. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +5 -4
  127. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -2
  128. data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
  129. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +12 -10
  130. data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
  131. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +35 -17
  132. data/lib/axlsx/workbook/worksheet/row.rb +30 -22
  133. data/lib/axlsx/workbook/worksheet/row_breaks.rb +8 -7
  134. data/lib/axlsx/workbook/worksheet/selection.rb +16 -16
  135. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +10 -7
  136. data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
  137. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
  138. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +11 -7
  139. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +21 -20
  140. data/lib/axlsx/workbook/worksheet/sheet_view.rb +48 -53
  141. data/lib/axlsx/workbook/worksheet/table.rb +13 -13
  142. data/lib/axlsx/workbook/worksheet/table_style_info.rb +6 -5
  143. data/lib/axlsx/workbook/worksheet/tables.rb +7 -5
  144. data/lib/axlsx/workbook/worksheet/worksheet.rb +92 -63
  145. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +10 -8
  146. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
  147. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +9 -8
  148. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +7 -5
  149. data/lib/axlsx.rb +75 -47
  150. data/lib/caxlsx.rb +3 -2
  151. metadata +50 -44
@@ -1,4 +1,5 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # Data validation allows the validation of cell data
4
5
  #
@@ -23,7 +24,7 @@ module Axlsx
23
24
  # @option options [Boolean] showInputMessage - A boolean value indicating whether to display the input prompt message.
24
25
  # @option options [String] sqref - Range over which data validation is applied, in "A1:B2" format.
25
26
  # @option options [Symbol] type - The type of data validation.
26
- def initialize(options={})
27
+ def initialize(options = {})
27
28
  # defaults
28
29
  @formula1 = @formula2 = @error = @errorTitle = @operator = @prompt = @promptTitle = @sqref = nil
29
30
  @allowBlank = @showErrorMessage = true
@@ -176,92 +177,92 @@ module Axlsx
176
177
  # default none
177
178
  attr_reader :type
178
179
 
179
-
180
180
  # @see formula1
181
- def formula1=(v); Axlsx::validate_string(v); @formula1 = v end
181
+ def formula1=(v); Axlsx.validate_string(v); @formula1 = v end
182
182
 
183
183
  # @see formula2
184
- def formula2=(v); Axlsx::validate_string(v); @formula2 = v end
184
+ def formula2=(v); Axlsx.validate_string(v); @formula2 = v end
185
185
 
186
186
  # @see allowBlank
187
- def allowBlank=(v); Axlsx::validate_boolean(v); @allowBlank = v end
187
+ def allowBlank=(v); Axlsx.validate_boolean(v); @allowBlank = v end
188
188
 
189
189
  # @see error
190
- def error=(v); Axlsx::validate_string(v); @error = v end
190
+ def error=(v); Axlsx.validate_string(v); @error = v end
191
191
 
192
192
  # @see errorStyle
193
- def errorStyle=(v); Axlsx::validate_data_validation_error_style(v); @errorStyle = v end
193
+ def errorStyle=(v); Axlsx.validate_data_validation_error_style(v); @errorStyle = v end
194
194
 
195
195
  # @see errorTitle
196
- def errorTitle=(v); Axlsx::validate_string(v); @errorTitle = v end
196
+ def errorTitle=(v); Axlsx.validate_string(v); @errorTitle = v end
197
197
 
198
198
  # @see operator
199
- def operator=(v); Axlsx::validate_data_validation_operator(v); @operator = v end
199
+ def operator=(v); Axlsx.validate_data_validation_operator(v); @operator = v end
200
200
 
201
201
  # @see prompt
202
- def prompt=(v); Axlsx::validate_string(v); @prompt = v end
202
+ def prompt=(v); Axlsx.validate_string(v); @prompt = v end
203
203
 
204
204
  # @see promptTitle
205
- def promptTitle=(v); Axlsx::validate_string(v); @promptTitle = v end
205
+ def promptTitle=(v); Axlsx.validate_string(v); @promptTitle = v end
206
206
 
207
207
  # @see showDropDown
208
208
  def showDropDown=(v)
209
209
  warn 'The `showDropDown` has an inverted logic, false shows the dropdown list! You should use `hideDropDown` instead.'
210
- Axlsx::validate_boolean(v)
210
+ Axlsx.validate_boolean(v)
211
211
  @showDropDown = v
212
212
  end
213
213
 
214
214
  # @see hideDropDown
215
215
  def hideDropDown=(v)
216
- Axlsx::validate_boolean(v)
216
+ Axlsx.validate_boolean(v)
217
217
  # It's just an alias for the showDropDown attribute, hideDropDown should set the value of the original showDropDown.
218
218
  @showDropDown = v
219
219
  end
220
220
 
221
221
  # @see showErrorMessage
222
- def showErrorMessage=(v); Axlsx::validate_boolean(v); @showErrorMessage = v end
222
+ def showErrorMessage=(v); Axlsx.validate_boolean(v); @showErrorMessage = v end
223
223
 
224
224
  # @see showInputMessage
225
- def showInputMessage=(v); Axlsx::validate_boolean(v); @showInputMessage = v end
225
+ def showInputMessage=(v); Axlsx.validate_boolean(v); @showInputMessage = v end
226
226
 
227
227
  # @see sqref
228
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
228
+ def sqref=(v); Axlsx.validate_string(v); @sqref = v end
229
229
 
230
230
  # @see type
231
- def type=(v); Axlsx::validate_data_validation_type(v); @type = v end
231
+ def type=(v); Axlsx.validate_data_validation_type(v); @type = v end
232
232
 
233
233
  # Serializes the data validation
234
234
  # @param [String] str
235
235
  # @return [String]
236
- def to_xml_string(str = '')
236
+ def to_xml_string(str = +'')
237
237
  valid_attributes = get_valid_attributes
238
+ h = Axlsx.instance_values_for(self).select { |key, _| valid_attributes.include?(key.to_sym) && !CHILD_ELEMENTS.include?(key.to_sym) }
238
239
 
239
240
  str << '<dataValidation '
240
- str << Axlsx.instance_values_for(self).map do |key, value|
241
- '' << key << '="' << Axlsx.booleanize(value).to_s << '"' if (valid_attributes.include?(key.to_sym) && !CHILD_ELEMENTS.include?(key.to_sym))
242
- end.join(' ')
241
+ h.each_with_index do |key_value, index|
242
+ str << ' ' unless index.zero?
243
+ str << key_value.first << '="' << Axlsx.booleanize(key_value.last).to_s << '"'
244
+ end
243
245
  str << '>'
244
- str << ('<formula1>' << self.formula1 << '</formula1>') if @formula1 and valid_attributes.include?(:formula1)
245
- str << ('<formula2>' << self.formula2 << '</formula2>') if @formula2 and valid_attributes.include?(:formula2)
246
+ str << '<formula1>' << formula1 << '</formula1>' if formula1 && valid_attributes.include?(:formula1)
247
+ str << '<formula2>' << formula2 << '</formula2>' if formula2 && valid_attributes.include?(:formula2)
246
248
  str << '</dataValidation>'
247
249
  end
248
250
 
249
- private
251
+ private
252
+
250
253
  def get_valid_attributes
251
- attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type ]
254
+ attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type]
252
255
 
253
256
  if [:whole, :decimal, :data, :time, :date, :textLength].include?(@type)
254
- attributes << [:operator, :formula1]
255
- attributes << [:formula2] if [:between, :notBetween].include?(@operator)
257
+ attributes << :operator << :formula1
258
+ attributes << :formula2 if [:between, :notBetween].include?(@operator)
256
259
  elsif @type == :list
257
- attributes << [:showDropDown, :formula1]
260
+ attributes << :showDropDown << :formula1
258
261
  elsif @type == :custom
259
- attributes << [:formula1]
260
- else
261
- attributes = []
262
+ attributes << :formula1
262
263
  end
263
264
 
264
- attributes.flatten!
265
+ attributes
265
266
  end
266
267
  end
267
268
  end
@@ -1,11 +1,12 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # A simple, self serializing class for storing conditional formattings
4
5
  class DataValidations < SimpleTypedList
5
-
6
6
  # creates a new Tables object
7
7
  def initialize(worksheet)
8
8
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
9
+
9
10
  super DataValidation
10
11
  @worksheet = worksheet
11
12
  end
@@ -15,14 +16,12 @@ module Axlsx
15
16
  attr_reader :worksheet
16
17
 
17
18
  # serialize the conditional formattings
18
- def to_xml_string(str = "")
19
+ def to_xml_string(str = +'')
19
20
  return if empty?
21
+
20
22
  str << "<dataValidations count='#{size}'>"
21
23
  each { |item| item.to_xml_string(str) }
22
24
  str << '</dataValidations>'
23
25
  end
24
26
  end
25
-
26
27
  end
27
-
28
-
@@ -1,20 +1,20 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  require "date"
3
4
 
4
5
  module Axlsx
5
- # The DateTimeConverter class converts both data and time types to their apprpriate excel serializations
6
+ # The DateTimeConverter class converts both data and time types to their apprpriate Excel serializations
6
7
  class DateTimeConverter
7
-
8
- # The date_to_serial method converts Date objects to the equivelant excel serialized forms
8
+ # The date_to_serial method converts Date objects to the equivelant Excel serialized forms
9
9
  # @param [Date] date the date to be serialized
10
10
  # @return [Numeric]
11
11
  def self.date_to_serial(date)
12
- epoch = Axlsx::Workbook::date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
12
+ epoch = Axlsx::Workbook.date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
13
13
  offset_date = date.respond_to?(:utc_offset) ? date + date.utc_offset.seconds : date
14
14
  (offset_date - epoch).to_f
15
15
  end
16
16
 
17
- # The time_to_serial methond converts a Time object its excel serialized form.
17
+ # The time_to_serial methond converts a Time object its Excel serialized form.
18
18
  # @param [Time] time the time to be serialized
19
19
  # @return [Numeric]
20
20
  def self.time_to_serial(time)
@@ -23,8 +23,8 @@ module Axlsx
23
23
  epoch1900 = -2209161600.0 # Time.utc(1899, 12, 30).to_i
24
24
  epoch1904 = -2082844800.0 # Time.utc(1904, 1, 1).to_i
25
25
  seconds_per_day = 86400.0 # 60*60*24
26
- epoch = Axlsx::Workbook::date1904 ? epoch1904 : epoch1900
27
- (time.utc_offset + time.to_f - epoch)/seconds_per_day
26
+ epoch = Axlsx::Workbook.date1904 ? epoch1904 : epoch1900
27
+ (time.utc_offset + time.to_f - epoch) / seconds_per_day
28
28
  end
29
29
  end
30
30
  end
@@ -1,10 +1,10 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # This class manages the dimensions for a worksheet.
4
- # While this node is optional in the specification some readers like
5
+ # While this node is optional in the specification some readers like
5
6
  # LibraOffice require this node to render the sheet
6
7
  class Dimension
7
-
8
8
  # the default value for the first cell in the dimension
9
9
  # @return [String]
10
10
  def self.default_first
@@ -22,6 +22,7 @@ module Axlsx
22
22
  # to.
23
23
  def initialize(worksheet)
24
24
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
25
+
25
26
  @worksheet = worksheet
26
27
  end
27
28
 
@@ -31,13 +32,14 @@ module Axlsx
31
32
  # @return [String]
32
33
  def sqref
33
34
  "#{first_cell_reference}:#{last_cell_reference}"
34
- end
35
+ end
35
36
 
36
37
  # serialize the object
37
38
  # @return [String]
38
- def to_xml_string(str = '')
39
+ def to_xml_string(str = +'')
39
40
  return if worksheet.rows.empty?
40
- str << "<dimension ref=\"%s\"></dimension>" % sqref
41
+
42
+ str << '<dimension ref="' << sqref << '"></dimension>'
41
43
  end
42
44
 
43
45
  # The first cell in the dimension
@@ -58,6 +60,7 @@ module Axlsx
58
60
  # @return [String]
59
61
  def dimension_reference(cell, default)
60
62
  return default unless cell.respond_to?(:r)
63
+
61
64
  cell.r
62
65
  end
63
66
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Header/Footer options for printing a worksheet. All settings are optional.
3
5
  #
@@ -9,7 +11,6 @@ module Axlsx
9
11
  # @note The recommended way of managing header/footers is via Worksheet#header_footer
10
12
  # @see Worksheet#initialize
11
13
  class HeaderFooter
12
-
13
14
  include Axlsx::OptionsParser
14
15
  include Axlsx::SerializedAttributes
15
16
  include Axlsx::Accessors
@@ -41,10 +42,10 @@ module Axlsx
41
42
  # Serializes the header/footer object.
42
43
  # @param [String] str
43
44
  # @return [String]
44
- def to_xml_string(str = '')
45
+ def to_xml_string(str = +'')
45
46
  serialized_tag('headerFooter', str) do
46
47
  serialized_element_attributes(str) do |value|
47
- value = ::CGI.escapeHTML(value)
48
+ ::CGI.escapeHTML(value)
48
49
  end
49
50
  end
50
51
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Conditional Format Rule icon sets
3
5
  # Describes an icon set conditional formatting rule.
@@ -6,7 +8,6 @@ module Axlsx
6
8
  # @see Worksheet#add_conditional_formatting
7
9
  # @see ConditionalFormattingRule#initialize
8
10
  class IconSet
9
-
10
11
  include Axlsx::OptionsParser
11
12
  include Axlsx::SerializedAttributes
12
13
 
@@ -19,8 +20,10 @@ module Axlsx
19
20
  @percent = @showValue = true
20
21
  @reverse = false
21
22
  @iconSet = "3TrafficLights1"
22
- initialize_value_objects
23
+ @interpolationPoints = [0, 33, 67]
24
+
23
25
  parse_options options
26
+
24
27
  yield self if block_given?
25
28
  end
26
29
 
@@ -33,7 +36,7 @@ module Axlsx
33
36
  attr_reader :iconSet
34
37
 
35
38
  # Indicates whether the thresholds indicate percentile values, instead of number values.
36
- # The default falue is true
39
+ # The default value is true
37
40
  # @return [Boolean]
38
41
  attr_reader :percent
39
42
 
@@ -47,8 +50,20 @@ module Axlsx
47
50
  # @return [Boolean]
48
51
  attr_reader :showValue
49
52
 
50
- # @see iconSet
51
- def iconSet=(v); Axlsx::validate_icon_set(v); @iconSet = v end
53
+ # Sets the values of the interpolation points in the scale.
54
+ # The default value is [0, 33, 67]
55
+ # @return [Integer]
56
+ attr_reader :interpolationPoints
57
+
58
+ # @see iconSet
59
+ def iconSet=(v); Axlsx.validate_icon_set(v); @iconSet = v end
60
+
61
+ # @see interpolationPoints
62
+ def interpolationPoints=(v)
63
+ v.each { |point| Axlsx.validate_int(point) }
64
+ @value_objects = nil
65
+ @interpolationPoints = v
66
+ end
52
67
 
53
68
  # @see showValue
54
69
  def showValue=(v); Axlsx.validate_boolean(v); @showValue = v end
@@ -62,7 +77,9 @@ module Axlsx
62
77
  # Serialize this object to an xml string
63
78
  # @param [String] str
64
79
  # @return [String]
65
- def to_xml_string(str="")
80
+ def to_xml_string(str = +'')
81
+ initialize_value_objects if @value_objects.nil?
82
+
66
83
  serialized_tag('iconSet', str) do
67
84
  @value_objects.each { |cfvo| cfvo.to_xml_string(str) }
68
85
  end
@@ -71,10 +88,9 @@ module Axlsx
71
88
  private
72
89
 
73
90
  # Initalize the simple typed list of value objects
74
- # I am keeping this private for now as I am not sure what impact changes to the required two cfvo objects will do.
75
91
  def initialize_value_objects
76
92
  @value_objects = SimpleTypedList.new Cfvo
77
- @value_objects.concat [Cfvo.new(:type => :percent, :val => 0), Cfvo.new(:type => :percent, :val => 33), Cfvo.new(:type => :percent, :val => 67)]
93
+ @interpolationPoints.each { |point| @value_objects << Cfvo.new(type: :percent, val: point) }
78
94
  @value_objects.lock
79
95
  end
80
96
  end
@@ -1,34 +1,34 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # A simple list of merged cells
4
5
  class MergedCells < SimpleTypedList
5
-
6
6
  # creates a new MergedCells object
7
7
  # @param [Worksheet] worksheet
8
8
  def initialize(worksheet)
9
9
  raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)
10
+
10
11
  super String
11
12
  end
12
13
 
13
14
  # adds cells to the merged cells collection
14
- # @param [Array||String] cells The cells to add to the merged cells
15
+ # @param [Array|String] cells The cells to add to the merged cells
15
16
  # collection. This can be an array of actual cells or a string style
16
17
  # range like 'A1:C1'
17
18
  def add(cells)
18
19
  self << if cells.is_a?(String)
19
- cells
20
- elsif cells.is_a?(Array)
21
- Axlsx::cell_range(cells, false)
22
- elsif cells.is_a?(Row)
23
- Axlsx::cell_range(cells, false)
24
- end
20
+ cells
21
+ elsif cells.is_a?(Array)
22
+ Axlsx.cell_range(cells, false)
23
+ end
25
24
  end
26
25
 
27
26
  # serialize the object
28
27
  # @param [String] str
29
28
  # @return [String]
30
- def to_xml_string(str = '')
29
+ def to_xml_string(str = +'')
31
30
  return if empty?
31
+
32
32
  str << "<mergeCells count='#{size}'>"
33
33
  each { |merged_cell| str << "<mergeCell ref='#{merged_cell}'></mergeCell>" }
34
34
  str << '</mergeCells>'
@@ -1,5 +1,6 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # The OutlinePr class manages serialization of a worksheet's outlinePr element, which provides various
4
5
  # options to control outlining.
5
6
  class OutlinePr
@@ -26,8 +27,10 @@ module Axlsx
26
27
  # Serialize the object
27
28
  # @param [String] str serialized output will be appended to this object if provided.
28
29
  # @return [String]
29
- def to_xml_string(str = '')
30
- str << "<outlinePr #{serialized_attributes} />"
30
+ def to_xml_string(str = +'')
31
+ str << '<outlinePr '
32
+ serialized_attributes(str)
33
+ str << '/>'
31
34
  end
32
35
  end
33
36
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # PageMargins specify the margins when printing a worksheet.
3
5
  #
@@ -9,7 +11,6 @@ module Axlsx
9
11
  # @see Worksheet#page_margins
10
12
  # @see Worksheet#initialize
11
13
  class PageMargins
12
-
13
14
  include Axlsx::OptionsParser
14
15
  include Axlsx::SerializedAttributes
15
16
 
@@ -20,7 +21,7 @@ module Axlsx
20
21
  # @option options [Numeric] top The top margin in inches
21
22
  # @option options [Numeric] header The header margin in inches
22
23
  # @option options [Numeric] footer The footer margin in inches
23
- def initialize(options={})
24
+ def initialize(options = {})
24
25
  # Default values taken from MS Excel for Mac 2011
25
26
  @left = @right = DEFAULT_LEFT_RIGHT
26
27
  @top = @bottom = DEFAULT_TOP_BOTTOM
@@ -28,7 +29,10 @@ module Axlsx
28
29
  parse_options options
29
30
  end
30
31
 
31
- serializable_attributes :left, :right, :bottom, :top, :header, :footer
32
+ # Possible margins to set
33
+ MARGIN_KEYS = [:left, :right, :top, :bottom, :header, :footer].freeze
34
+
35
+ serializable_attributes(*MARGIN_KEYS)
32
36
 
33
37
  # Default left and right margin (in inches)
34
38
  DEFAULT_LEFT_RIGHT = 0.75
@@ -64,33 +68,34 @@ module Axlsx
64
68
  attr_reader :footer
65
69
 
66
70
  # Set some or all margins at once.
67
- # @param [Hash] margins the margins to set (possible keys are :left, :right, :top, :bottom, :header and :footer).
71
+ # @param [Hash] margins the margins to set. See {MARGIN_KEYS} for a list of possible keys.
68
72
  def set(margins)
69
73
  margins.select do |k, v|
70
- next unless [:left, :right, :top, :bottom, :header, :footer].include? k
74
+ next unless MARGIN_KEYS.include? k
75
+
71
76
  send("#{k}=", v)
72
77
  end
73
78
  end
74
79
 
75
80
  # @see left
76
- def left=(v); Axlsx::validate_unsigned_numeric(v); @left = v end
81
+ def left=(v); Axlsx.validate_unsigned_numeric(v); @left = v end
77
82
  # @see right
78
- def right=(v); Axlsx::validate_unsigned_numeric(v); @right = v end
83
+ def right=(v); Axlsx.validate_unsigned_numeric(v); @right = v end
79
84
  # @see top
80
- def top=(v); Axlsx::validate_unsigned_numeric(v); @top = v end
85
+ def top=(v); Axlsx.validate_unsigned_numeric(v); @top = v end
81
86
  # @see bottom
82
- def bottom=(v); Axlsx::validate_unsigned_numeric(v); @bottom = v end
87
+ def bottom=(v); Axlsx.validate_unsigned_numeric(v); @bottom = v end
83
88
  # @see header
84
- def header=(v); Axlsx::validate_unsigned_numeric(v); @header = v end
89
+ def header=(v); Axlsx.validate_unsigned_numeric(v); @header = v end
85
90
  # @see footer
86
- def footer=(v); Axlsx::validate_unsigned_numeric(v); @footer = v end
91
+ def footer=(v); Axlsx.validate_unsigned_numeric(v); @footer = v end
87
92
 
88
93
  # Serializes the page margins element
89
94
  # @param [String] str
90
95
  # @return [String]
91
96
  # @note For compatibility, this is a noop unless custom margins have been specified.
92
97
  # @see #custom_margins_specified?
93
- def to_xml_string(str = '')
98
+ def to_xml_string(str = +'')
94
99
  serialized_tag('pageMargins', str)
95
100
  end
96
101
  end
@@ -1,9 +1,9 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # Page setup properties of the worksheet
4
5
  # This class name is not a typo, its spec.
5
6
  class PageSetUpPr
6
-
7
7
  include Axlsx::OptionsParser
8
8
  include Axlsx::SerializedAttributes
9
9
 
@@ -37,8 +37,10 @@ module Axlsx
37
37
  end
38
38
 
39
39
  # serialize to xml
40
- def to_xml_string(str='')
41
- str << ('<pageSetUpPr ' << serialized_attributes << '/>')
40
+ def to_xml_string(str = +'')
41
+ str << '<pageSetUpPr '
42
+ serialized_attributes(str)
43
+ str << '/>'
42
44
  end
43
45
  end
44
46
  end