caxlsx 3.4.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -1
  3. data/README.md +9 -11
  4. data/Rakefile +7 -5
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +12 -4
  7. data/lib/axlsx/content_type/content_type.rb +8 -6
  8. data/lib/axlsx/content_type/default.rb +7 -2
  9. data/lib/axlsx/content_type/override.rb +7 -2
  10. data/lib/axlsx/doc_props/app.rb +95 -26
  11. data/lib/axlsx/doc_props/core.rb +8 -6
  12. data/lib/axlsx/drawing/area_chart.rb +10 -8
  13. data/lib/axlsx/drawing/area_series.rb +20 -12
  14. data/lib/axlsx/drawing/ax_data_source.rb +2 -0
  15. data/lib/axlsx/drawing/axes.rb +6 -4
  16. data/lib/axlsx/drawing/axis.rb +42 -22
  17. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -12
  18. data/lib/axlsx/drawing/bar_chart.rb +13 -11
  19. data/lib/axlsx/drawing/bar_series.rb +20 -9
  20. data/lib/axlsx/drawing/bubble_chart.rb +6 -4
  21. data/lib/axlsx/drawing/bubble_series.rb +8 -6
  22. data/lib/axlsx/drawing/cat_axis.rb +29 -12
  23. data/lib/axlsx/drawing/chart.rb +46 -20
  24. data/lib/axlsx/drawing/d_lbls.rb +10 -8
  25. data/lib/axlsx/drawing/drawing.rb +59 -56
  26. data/lib/axlsx/drawing/graphic_frame.rb +6 -4
  27. data/lib/axlsx/drawing/hyperlink.rb +19 -8
  28. data/lib/axlsx/drawing/line_3D_chart.rb +7 -5
  29. data/lib/axlsx/drawing/line_chart.rb +10 -8
  30. data/lib/axlsx/drawing/line_series.rb +20 -12
  31. data/lib/axlsx/drawing/marker.rb +24 -7
  32. data/lib/axlsx/drawing/num_data.rb +9 -7
  33. data/lib/axlsx/drawing/num_data_source.rb +9 -7
  34. data/lib/axlsx/drawing/num_val.rb +7 -5
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +13 -5
  36. data/lib/axlsx/drawing/pic.rb +26 -15
  37. data/lib/axlsx/drawing/picture_locking.rb +3 -1
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +6 -4
  39. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  40. data/lib/axlsx/drawing/pie_series.rb +23 -9
  41. data/lib/axlsx/drawing/scaling.rb +25 -9
  42. data/lib/axlsx/drawing/scatter_chart.rb +7 -5
  43. data/lib/axlsx/drawing/scatter_series.rb +14 -12
  44. data/lib/axlsx/drawing/ser_axis.rb +13 -5
  45. data/lib/axlsx/drawing/series.rb +13 -5
  46. data/lib/axlsx/drawing/series_title.rb +6 -4
  47. data/lib/axlsx/drawing/str_data.rb +7 -5
  48. data/lib/axlsx/drawing/str_val.rb +6 -4
  49. data/lib/axlsx/drawing/title.rb +13 -14
  50. data/lib/axlsx/drawing/two_cell_anchor.rb +4 -2
  51. data/lib/axlsx/drawing/val_axis.rb +4 -2
  52. data/lib/axlsx/drawing/view_3D.rb +16 -8
  53. data/lib/axlsx/drawing/vml_drawing.rb +18 -16
  54. data/lib/axlsx/drawing/vml_shape.rb +24 -22
  55. data/lib/axlsx/package.rb +73 -67
  56. data/lib/axlsx/rels/relationship.rb +21 -6
  57. data/lib/axlsx/rels/relationships.rb +6 -4
  58. data/lib/axlsx/stylesheet/border.rb +15 -4
  59. data/lib/axlsx/stylesheet/border_pr.rb +19 -6
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +41 -10
  61. data/lib/axlsx/stylesheet/cell_protection.rb +12 -3
  62. data/lib/axlsx/stylesheet/cell_style.rb +33 -8
  63. data/lib/axlsx/stylesheet/color.rb +15 -7
  64. data/lib/axlsx/stylesheet/dxf.rb +34 -9
  65. data/lib/axlsx/stylesheet/fill.rb +7 -2
  66. data/lib/axlsx/stylesheet/font.rb +65 -17
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +12 -4
  68. data/lib/axlsx/stylesheet/gradient_stop.rb +14 -5
  69. data/lib/axlsx/stylesheet/num_fmt.rb +14 -10
  70. data/lib/axlsx/stylesheet/pattern_fill.rb +18 -5
  71. data/lib/axlsx/stylesheet/styles.rb +124 -82
  72. data/lib/axlsx/stylesheet/table_style.rb +19 -6
  73. data/lib/axlsx/stylesheet/table_style_element.rb +15 -4
  74. data/lib/axlsx/stylesheet/table_styles.rb +14 -5
  75. data/lib/axlsx/stylesheet/xf.rb +73 -18
  76. data/lib/axlsx/util/accessors.rb +10 -6
  77. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  78. data/lib/axlsx/util/constants.rb +117 -104
  79. data/lib/axlsx/util/mime_type_utils.rb +3 -5
  80. data/lib/axlsx/util/options_parser.rb +3 -1
  81. data/lib/axlsx/util/serialized_attributes.rb +42 -17
  82. data/lib/axlsx/util/simple_typed_list.rb +47 -47
  83. data/lib/axlsx/util/storage.rb +11 -10
  84. data/lib/axlsx/util/validators.rb +101 -41
  85. data/lib/axlsx/util/zip_command.rb +10 -10
  86. data/lib/axlsx/version.rb +3 -1
  87. data/lib/axlsx/workbook/defined_name.rb +6 -4
  88. data/lib/axlsx/workbook/defined_names.rb +4 -2
  89. data/lib/axlsx/workbook/shared_strings_table.rb +8 -6
  90. data/lib/axlsx/workbook/workbook.rb +94 -79
  91. data/lib/axlsx/workbook/workbook_view.rb +3 -1
  92. data/lib/axlsx/workbook/workbook_views.rb +4 -2
  93. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +65 -8
  94. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -5
  95. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +11 -7
  96. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  97. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
  98. data/lib/axlsx/workbook/worksheet/border_creator.rb +5 -3
  99. data/lib/axlsx/workbook/worksheet/break.rb +3 -1
  100. data/lib/axlsx/workbook/worksheet/cell.rb +83 -64
  101. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +31 -27
  102. data/lib/axlsx/workbook/worksheet/cfvo.rb +11 -3
  103. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -1
  104. data/lib/axlsx/workbook/worksheet/col.rb +5 -3
  105. data/lib/axlsx/workbook/worksheet/col_breaks.rb +6 -4
  106. data/lib/axlsx/workbook/worksheet/color_scale.rb +12 -10
  107. data/lib/axlsx/workbook/worksheet/cols.rb +4 -2
  108. data/lib/axlsx/workbook/worksheet/comment.rb +8 -6
  109. data/lib/axlsx/workbook/worksheet/comments.rb +6 -4
  110. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +16 -5
  111. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +73 -16
  112. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +4 -2
  113. data/lib/axlsx/workbook/worksheet/data_bar.rb +14 -13
  114. data/lib/axlsx/workbook/worksheet/data_validation.rb +69 -28
  115. data/lib/axlsx/workbook/worksheet/data_validations.rb +4 -2
  116. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +7 -5
  117. data/lib/axlsx/workbook/worksheet/dimension.rb +4 -2
  118. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -2
  119. data/lib/axlsx/workbook/worksheet/icon_set.rb +38 -9
  120. data/lib/axlsx/workbook/worksheet/merged_cells.rb +6 -6
  121. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -2
  122. data/lib/axlsx/workbook/worksheet/page_margins.rb +39 -11
  123. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -4
  124. data/lib/axlsx/workbook/worksheet/page_setup.rb +34 -9
  125. data/lib/axlsx/workbook/worksheet/pane.rb +17 -9
  126. data/lib/axlsx/workbook/worksheet/pivot_table.rb +20 -19
  127. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -6
  128. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -1
  129. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -1
  130. data/lib/axlsx/workbook/worksheet/protected_range.rb +3 -1
  131. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +6 -4
  132. data/lib/axlsx/workbook/worksheet/rich_text.rb +3 -1
  133. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +46 -24
  134. data/lib/axlsx/workbook/worksheet/row.rb +11 -9
  135. data/lib/axlsx/workbook/worksheet/row_breaks.rb +7 -5
  136. data/lib/axlsx/workbook/worksheet/selection.rb +15 -7
  137. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -2
  138. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  139. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +6 -2
  140. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +8 -4
  141. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +11 -9
  142. data/lib/axlsx/workbook/worksheet/sheet_view.rb +38 -15
  143. data/lib/axlsx/workbook/worksheet/table.rb +9 -7
  144. data/lib/axlsx/workbook/worksheet/table_style_info.rb +4 -2
  145. data/lib/axlsx/workbook/worksheet/tables.rb +4 -2
  146. data/lib/axlsx/workbook/worksheet/worksheet.rb +56 -39
  147. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -2
  148. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +8 -2
  149. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +7 -5
  150. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +5 -3
  151. data/lib/axlsx.rb +56 -42
  152. data/lib/caxlsx.rb +3 -1
  153. metadata +39 -71
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Conditional Format Rule data bar object
3
5
  # Describes a data bar conditional formatting rule.
@@ -12,8 +14,8 @@ module Axlsx
12
14
  class << self
13
15
  # This differs from ColorScale. There must be exactly two cfvos one color
14
16
  def default_cfvos
15
- [{ :type => :min, :val => "0" },
16
- { :type => :max, :val => "0" }]
17
+ [{ type: :min, val: "0" },
18
+ { type: :max, val: "0" }]
17
19
  end
18
20
  end
19
21
 
@@ -36,7 +38,7 @@ module Axlsx
36
38
  serializable_attributes :min_length, :max_length, :show_value
37
39
 
38
40
  # instance values that must be serialized as their own elements - e.g. not attributes.
39
- CHILD_ELEMENTS = [:value_objects, :color]
41
+ CHILD_ELEMENTS = [:value_objects, :color].freeze
40
42
 
41
43
  # minLength attribute
42
44
  # The minimum length of the data bar, as a percentage of the cell width.
@@ -70,7 +72,7 @@ module Axlsx
70
72
  # the color object used in the data bar formatting
71
73
  # @return [Color]
72
74
  def color
73
- @color ||= Color.new :rgb => "FF0000FF"
75
+ @color ||= Color.new rgb: "FF0000FF"
74
76
  end
75
77
 
76
78
  # @see minLength
@@ -98,17 +100,16 @@ module Axlsx
98
100
  # @param [Color|String] v The color object, or rgb string value to apply
99
101
  def color=(v)
100
102
  @color = v if v.is_a? Color
101
- self.color.rgb = v if v.is_a? String
102
- @color
103
+ color.rgb = v if v.is_a? String
103
104
  end
104
105
 
105
106
  # Serialize this object to an xml string
106
107
  # @param [String] str
107
108
  # @return [String]
108
- def to_xml_string(str = "")
109
+ def to_xml_string(str = +'')
109
110
  serialized_tag('dataBar', str) do
110
111
  value_objects.to_xml_string(str)
111
- self.color.to_xml_string(str)
112
+ color.to_xml_string(str)
112
113
  end
113
114
  end
114
115
 
@@ -116,11 +117,11 @@ module Axlsx
116
117
 
117
118
  def initialize_cfvos(cfvos)
118
119
  self.class.default_cfvos.each_with_index.map do |default, index|
119
- if index < cfvos.size
120
- value_objects << Cfvo.new(default.merge(cfvos[index]))
121
- else
122
- value_objects << Cfvo.new(default)
123
- end
120
+ value_objects << if index < cfvos.size
121
+ Cfvo.new(default.merge(cfvos[index]))
122
+ else
123
+ Cfvo.new(default)
124
+ end
124
125
  end
125
126
  end
126
127
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Data validation allows the validation of cell data
3
5
  #
@@ -176,71 +178,112 @@ module Axlsx
176
178
  attr_reader :type
177
179
 
178
180
  # @see formula1
179
- def formula1=(v); Axlsx::validate_string(v); @formula1 = v end
181
+ def formula1=(v)
182
+ Axlsx.validate_string(v)
183
+ @formula1 = v
184
+ end
180
185
 
181
186
  # @see formula2
182
- def formula2=(v); Axlsx::validate_string(v); @formula2 = v end
187
+ def formula2=(v)
188
+ Axlsx.validate_string(v)
189
+ @formula2 = v
190
+ end
183
191
 
184
192
  # @see allowBlank
185
- def allowBlank=(v); Axlsx::validate_boolean(v); @allowBlank = v end
193
+ def allowBlank=(v)
194
+ Axlsx.validate_boolean(v)
195
+ @allowBlank = v
196
+ end
186
197
 
187
198
  # @see error
188
- def error=(v); Axlsx::validate_string(v); @error = v end
199
+ def error=(v)
200
+ Axlsx.validate_string(v)
201
+ @error = v
202
+ end
189
203
 
190
204
  # @see errorStyle
191
- def errorStyle=(v); Axlsx::validate_data_validation_error_style(v); @errorStyle = v end
205
+ def errorStyle=(v)
206
+ Axlsx.validate_data_validation_error_style(v)
207
+ @errorStyle = v
208
+ end
192
209
 
193
210
  # @see errorTitle
194
- def errorTitle=(v); Axlsx::validate_string(v); @errorTitle = v end
211
+ def errorTitle=(v)
212
+ Axlsx.validate_string(v)
213
+ @errorTitle = v
214
+ end
195
215
 
196
216
  # @see operator
197
- def operator=(v); Axlsx::validate_data_validation_operator(v); @operator = v end
217
+ def operator=(v)
218
+ Axlsx.validate_data_validation_operator(v)
219
+ @operator = v
220
+ end
198
221
 
199
222
  # @see prompt
200
- def prompt=(v); Axlsx::validate_string(v); @prompt = v end
223
+ def prompt=(v)
224
+ Axlsx.validate_string(v)
225
+ @prompt = v
226
+ end
201
227
 
202
228
  # @see promptTitle
203
- def promptTitle=(v); Axlsx::validate_string(v); @promptTitle = v end
229
+ def promptTitle=(v)
230
+ Axlsx.validate_string(v)
231
+ @promptTitle = v
232
+ end
204
233
 
205
234
  # @see showDropDown
206
235
  def showDropDown=(v)
207
236
  warn 'The `showDropDown` has an inverted logic, false shows the dropdown list! You should use `hideDropDown` instead.'
208
- Axlsx::validate_boolean(v)
237
+ Axlsx.validate_boolean(v)
209
238
  @showDropDown = v
210
239
  end
211
240
 
212
241
  # @see hideDropDown
213
242
  def hideDropDown=(v)
214
- Axlsx::validate_boolean(v)
243
+ Axlsx.validate_boolean(v)
215
244
  # It's just an alias for the showDropDown attribute, hideDropDown should set the value of the original showDropDown.
216
245
  @showDropDown = v
217
246
  end
218
247
 
219
248
  # @see showErrorMessage
220
- def showErrorMessage=(v); Axlsx::validate_boolean(v); @showErrorMessage = v end
249
+ def showErrorMessage=(v)
250
+ Axlsx.validate_boolean(v)
251
+ @showErrorMessage = v
252
+ end
221
253
 
222
254
  # @see showInputMessage
223
- def showInputMessage=(v); Axlsx::validate_boolean(v); @showInputMessage = v end
255
+ def showInputMessage=(v)
256
+ Axlsx.validate_boolean(v)
257
+ @showInputMessage = v
258
+ end
224
259
 
225
260
  # @see sqref
226
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
261
+ def sqref=(v)
262
+ Axlsx.validate_string(v)
263
+ @sqref = v
264
+ end
227
265
 
228
266
  # @see type
229
- def type=(v); Axlsx::validate_data_validation_type(v); @type = v end
267
+ def type=(v)
268
+ Axlsx.validate_data_validation_type(v)
269
+ @type = v
270
+ end
230
271
 
231
272
  # Serializes the data validation
232
273
  # @param [String] str
233
274
  # @return [String]
234
- def to_xml_string(str = '')
275
+ def to_xml_string(str = +'')
235
276
  valid_attributes = get_valid_attributes
277
+ h = Axlsx.instance_values_for(self).select { |key, _| valid_attributes.include?(key.to_sym) && !CHILD_ELEMENTS.include?(key.to_sym) }
236
278
 
237
279
  str << '<dataValidation '
238
- str << Axlsx.instance_values_for(self).map do |key, value|
239
- '' << key << '="' << Axlsx.booleanize(value).to_s << '"' if (valid_attributes.include?(key.to_sym) && !CHILD_ELEMENTS.include?(key.to_sym))
240
- end.join(' ')
280
+ h.each_with_index do |key_value, index|
281
+ str << ' ' unless index.zero?
282
+ str << key_value.first << '="' << Axlsx.booleanize(key_value.last).to_s << '"'
283
+ end
241
284
  str << '>'
242
- str << ('<formula1>' << self.formula1 << '</formula1>') if @formula1 and valid_attributes.include?(:formula1)
243
- str << ('<formula2>' << self.formula2 << '</formula2>') if @formula2 and valid_attributes.include?(:formula2)
285
+ str << '<formula1>' << formula1 << '</formula1>' if formula1 && valid_attributes.include?(:formula1)
286
+ str << '<formula2>' << formula2 << '</formula2>' if formula2 && valid_attributes.include?(:formula2)
244
287
  str << '</dataValidation>'
245
288
  end
246
289
 
@@ -250,17 +293,15 @@ module Axlsx
250
293
  attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type]
251
294
 
252
295
  if [:whole, :decimal, :data, :time, :date, :textLength].include?(@type)
253
- attributes << [:operator, :formula1]
254
- attributes << [:formula2] if [:between, :notBetween].include?(@operator)
296
+ attributes << :operator << :formula1
297
+ attributes << :formula2 if [:between, :notBetween].include?(@operator)
255
298
  elsif @type == :list
256
- attributes << [:showDropDown, :formula1]
299
+ attributes << :showDropDown << :formula1
257
300
  elsif @type == :custom
258
- attributes << [:formula1]
259
- else
260
- attributes = []
301
+ attributes << :formula1
261
302
  end
262
303
 
263
- attributes.flatten!
304
+ attributes
264
305
  end
265
306
  end
266
307
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A simple, self serializing class for storing conditional formattings
3
5
  class DataValidations < SimpleTypedList
@@ -5,7 +7,7 @@ module Axlsx
5
7
  def initialize(worksheet)
6
8
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
7
9
 
8
- super DataValidation
10
+ super(DataValidation)
9
11
  @worksheet = worksheet
10
12
  end
11
13
 
@@ -14,7 +16,7 @@ module Axlsx
14
16
  attr_reader :worksheet
15
17
 
16
18
  # serialize the conditional formattings
17
- def to_xml_string(str = "")
19
+ def to_xml_string(str = +'')
18
20
  return if empty?
19
21
 
20
22
  str << "<dataValidations count='#{size}'>"
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "date"
2
4
 
3
5
  module Axlsx
4
- # 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
5
7
  class DateTimeConverter
6
- # 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
7
9
  # @param [Date] date the date to be serialized
8
10
  # @return [Numeric]
9
11
  def self.date_to_serial(date)
10
- 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)
11
13
  offset_date = date.respond_to?(:utc_offset) ? date + date.utc_offset.seconds : date
12
14
  (offset_date - epoch).to_f
13
15
  end
14
16
 
15
- # 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.
16
18
  # @param [Time] time the time to be serialized
17
19
  # @return [Numeric]
18
20
  def self.time_to_serial(time)
@@ -21,7 +23,7 @@ module Axlsx
21
23
  epoch1900 = -2209161600.0 # Time.utc(1899, 12, 30).to_i
22
24
  epoch1904 = -2082844800.0 # Time.utc(1904, 1, 1).to_i
23
25
  seconds_per_day = 86400.0 # 60*60*24
24
- epoch = Axlsx::Workbook::date1904 ? epoch1904 : epoch1900
26
+ epoch = Axlsx::Workbook.date1904 ? epoch1904 : epoch1900
25
27
  (time.utc_offset + time.to_f - epoch) / seconds_per_day
26
28
  end
27
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # This class manages the dimensions for a worksheet.
3
5
  # While this node is optional in the specification some readers like
@@ -34,10 +36,10 @@ module Axlsx
34
36
 
35
37
  # serialize the object
36
38
  # @return [String]
37
- def to_xml_string(str = '')
39
+ def to_xml_string(str = +'')
38
40
  return if worksheet.rows.empty?
39
41
 
40
- str << "<dimension ref=\"%s\"></dimension>" % sqref
42
+ str << '<dimension ref="' << sqref << '"></dimension>'
41
43
  end
42
44
 
43
45
  # The first cell in the dimension
@@ -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
  #
@@ -40,10 +42,10 @@ module Axlsx
40
42
  # Serializes the header/footer object.
41
43
  # @param [String] str
42
44
  # @return [String]
43
- def to_xml_string(str = '')
45
+ def to_xml_string(str = +'')
44
46
  serialized_tag('headerFooter', str) do
45
47
  serialized_element_attributes(str) do |value|
46
- value = ::CGI.escapeHTML(value)
48
+ ::CGI.escapeHTML(value)
47
49
  end
48
50
  end
49
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.
@@ -18,8 +20,10 @@ module Axlsx
18
20
  @percent = @showValue = true
19
21
  @reverse = false
20
22
  @iconSet = "3TrafficLights1"
21
- initialize_value_objects
23
+ @interpolationPoints = [0, 33, 67]
24
+
22
25
  parse_options options
26
+
23
27
  yield self if block_given?
24
28
  end
25
29
 
@@ -32,7 +36,7 @@ module Axlsx
32
36
  attr_reader :iconSet
33
37
 
34
38
  # Indicates whether the thresholds indicate percentile values, instead of number values.
35
- # The default falue is true
39
+ # The default value is true
36
40
  # @return [Boolean]
37
41
  attr_reader :percent
38
42
 
@@ -46,22 +50,48 @@ module Axlsx
46
50
  # @return [Boolean]
47
51
  attr_reader :showValue
48
52
 
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
+
49
58
  # @see iconSet
50
- def iconSet=(v); Axlsx::validate_icon_set(v); @iconSet = v end
59
+ def iconSet=(v)
60
+ Axlsx.validate_icon_set(v)
61
+ @iconSet = v
62
+ end
63
+
64
+ # @see interpolationPoints
65
+ def interpolationPoints=(v)
66
+ v.each { |point| Axlsx.validate_int(point) }
67
+ @value_objects = nil
68
+ @interpolationPoints = v
69
+ end
51
70
 
52
71
  # @see showValue
53
- def showValue=(v); Axlsx.validate_boolean(v); @showValue = v end
72
+ def showValue=(v)
73
+ Axlsx.validate_boolean(v)
74
+ @showValue = v
75
+ end
54
76
 
55
77
  # @see percent
56
- def percent=(v); Axlsx.validate_boolean(v); @percent = v end
78
+ def percent=(v)
79
+ Axlsx.validate_boolean(v)
80
+ @percent = v
81
+ end
57
82
 
58
83
  # @see reverse
59
- def reverse=(v); Axlsx.validate_boolean(v); @reverse = v end
84
+ def reverse=(v)
85
+ Axlsx.validate_boolean(v)
86
+ @reverse = v
87
+ end
60
88
 
61
89
  # Serialize this object to an xml string
62
90
  # @param [String] str
63
91
  # @return [String]
64
- def to_xml_string(str = "")
92
+ def to_xml_string(str = +'')
93
+ initialize_value_objects if @value_objects.nil?
94
+
65
95
  serialized_tag('iconSet', str) do
66
96
  @value_objects.each { |cfvo| cfvo.to_xml_string(str) }
67
97
  end
@@ -70,10 +100,9 @@ module Axlsx
70
100
  private
71
101
 
72
102
  # Initalize the simple typed list of value objects
73
- # I am keeping this private for now as I am not sure what impact changes to the required two cfvo objects will do.
74
103
  def initialize_value_objects
75
104
  @value_objects = SimpleTypedList.new Cfvo
76
- @value_objects.concat [Cfvo.new(:type => :percent, :val => 0), Cfvo.new(:type => :percent, :val => 33), Cfvo.new(:type => :percent, :val => 67)]
105
+ @interpolationPoints.each { |point| @value_objects << Cfvo.new(type: :percent, val: point) }
77
106
  @value_objects.lock
78
107
  end
79
108
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A simple list of merged cells
3
5
  class MergedCells < SimpleTypedList
@@ -6,27 +8,25 @@ module Axlsx
6
8
  def initialize(worksheet)
7
9
  raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)
8
10
 
9
- super String
11
+ super(String)
10
12
  end
11
13
 
12
14
  # adds cells to the merged cells collection
13
- # @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
14
16
  # collection. This can be an array of actual cells or a string style
15
17
  # range like 'A1:C1'
16
18
  def add(cells)
17
19
  self << if cells.is_a?(String)
18
20
  cells
19
21
  elsif cells.is_a?(Array)
20
- Axlsx::cell_range(cells, false)
21
- elsif cells.is_a?(Row)
22
- Axlsx::cell_range(cells, false)
22
+ Axlsx.cell_range(cells, false)
23
23
  end
24
24
  end
25
25
 
26
26
  # serialize the object
27
27
  # @param [String] str
28
28
  # @return [String]
29
- def to_xml_string(str = '')
29
+ def to_xml_string(str = +'')
30
30
  return if empty?
31
31
 
32
32
  str << "<mergeCells count='#{size}'>"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The OutlinePr class manages serialization of a worksheet's outlinePr element, which provides various
3
5
  # options to control outlining.
@@ -25,8 +27,10 @@ module Axlsx
25
27
  # Serialize the object
26
28
  # @param [String] str serialized output will be appended to this object if provided.
27
29
  # @return [String]
28
- def to_xml_string(str = '')
29
- str << "<outlinePr #{serialized_attributes} />"
30
+ def to_xml_string(str = +'')
31
+ str << '<outlinePr '
32
+ serialized_attributes(str)
33
+ str << '/>'
30
34
  end
31
35
  end
32
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
  #
@@ -27,7 +29,10 @@ module Axlsx
27
29
  parse_options options
28
30
  end
29
31
 
30
- 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)
31
36
 
32
37
  # Default left and right margin (in inches)
33
38
  DEFAULT_LEFT_RIGHT = 0.75
@@ -63,34 +68,57 @@ module Axlsx
63
68
  attr_reader :footer
64
69
 
65
70
  # Set some or all margins at once.
66
- # @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.
67
72
  def set(margins)
68
73
  margins.select do |k, v|
69
- next unless [:left, :right, :top, :bottom, :header, :footer].include? k
74
+ next unless MARGIN_KEYS.include? k
70
75
 
71
- send("#{k}=", v)
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)
82
+ Axlsx.validate_unsigned_numeric(v)
83
+ @left = v
84
+ end
85
+
77
86
  # @see right
78
- def right=(v); Axlsx::validate_unsigned_numeric(v); @right = v end
87
+ def right=(v)
88
+ Axlsx.validate_unsigned_numeric(v)
89
+ @right = v
90
+ end
91
+
79
92
  # @see top
80
- def top=(v); Axlsx::validate_unsigned_numeric(v); @top = v end
93
+ def top=(v)
94
+ Axlsx.validate_unsigned_numeric(v)
95
+ @top = v
96
+ end
97
+
81
98
  # @see bottom
82
- def bottom=(v); Axlsx::validate_unsigned_numeric(v); @bottom = v end
99
+ def bottom=(v)
100
+ Axlsx.validate_unsigned_numeric(v)
101
+ @bottom = v
102
+ end
103
+
83
104
  # @see header
84
- def header=(v); Axlsx::validate_unsigned_numeric(v); @header = v end
105
+ def header=(v)
106
+ Axlsx.validate_unsigned_numeric(v)
107
+ @header = v
108
+ end
109
+
85
110
  # @see footer
86
- def footer=(v); Axlsx::validate_unsigned_numeric(v); @footer = v end
111
+ def footer=(v)
112
+ Axlsx.validate_unsigned_numeric(v)
113
+ @footer = v
114
+ end
87
115
 
88
116
  # Serializes the page margins element
89
117
  # @param [String] str
90
118
  # @return [String]
91
119
  # @note For compatibility, this is a noop unless custom margins have been specified.
92
120
  # @see #custom_margins_specified?
93
- def to_xml_string(str = '')
121
+ def to_xml_string(str = +'')
94
122
  serialized_tag('pageMargins', str)
95
123
  end
96
124
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Page setup properties of the worksheet
3
5
  # This class name is not a typo, its spec.
@@ -15,8 +17,7 @@ module Axlsx
15
17
 
16
18
  serializable_attributes :auto_page_breaks, :fit_to_page
17
19
 
18
- attr_reader :auto_page_breaks
19
- attr_reader :fit_to_page
20
+ attr_reader :auto_page_breaks, :fit_to_page
20
21
 
21
22
  # Flag indicating whether the Fit to Page print option is enabled.
22
23
  # @param [Boolean] value
@@ -35,8 +36,10 @@ module Axlsx
35
36
  end
36
37
 
37
38
  # serialize to xml
38
- def to_xml_string(str = '')
39
- str << ('<pageSetUpPr ' << serialized_attributes << '/>')
39
+ def to_xml_string(str = +'')
40
+ str << '<pageSetUpPr '
41
+ serialized_attributes(str)
42
+ str << '/>'
40
43
  end
41
44
  end
42
45
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Page setup settings for printing a worksheet. All settings are optional.
3
5
  #
@@ -196,17 +198,40 @@ module Axlsx
196
198
  end
197
199
 
198
200
  # @see fit_to_height
199
- def fit_to_height=(v); Axlsx::validate_unsigned_int(v); @fit_to_height = v; end
201
+ def fit_to_height=(v)
202
+ Axlsx.validate_unsigned_int(v)
203
+ @fit_to_height = v
204
+ end
205
+
200
206
  # @see fit_to_width
201
- def fit_to_width=(v); Axlsx::validate_unsigned_int(v); @fit_to_width = v; end
207
+ def fit_to_width=(v)
208
+ Axlsx.validate_unsigned_int(v)
209
+ @fit_to_width = v
210
+ end
211
+
202
212
  # @see orientation
203
- def orientation=(v); Axlsx::validate_page_orientation(v); @orientation = v; end
213
+ def orientation=(v)
214
+ Axlsx.validate_page_orientation(v)
215
+ @orientation = v
216
+ end
217
+
204
218
  # @see paper_height
205
- def paper_height=(v); Axlsx::validate_number_with_unit(v); @paper_height = v; end
219
+ def paper_height=(v)
220
+ Axlsx.validate_number_with_unit(v)
221
+ @paper_height = v
222
+ end
223
+
206
224
  # @see paper_width
207
- def paper_width=(v); Axlsx::validate_number_with_unit(v); @paper_width = v; end
225
+ def paper_width=(v)
226
+ Axlsx.validate_number_with_unit(v)
227
+ @paper_width = v
228
+ end
229
+
208
230
  # @see scale
209
- def scale=(v); Axlsx::validate_scale_10_400(v); @scale = v; end
231
+ def scale=(v)
232
+ Axlsx.validate_scale_10_400(v)
233
+ @scale = v
234
+ end
210
235
 
211
236
  # convenience method to achieve sanity when setting fit_to_width and fit_to_height
212
237
  # as they both default to 1 if only their counterpart is specified.
@@ -223,14 +248,14 @@ module Axlsx
223
248
  # We treat any page set up that has a value set for fit_to_width or fit_to_height value as fit_to_page.
224
249
  # @return [Boolean]
225
250
  def fit_to_page?
226
- # is there some better what to express this?
227
- (fit_to_width != nil || fit_to_height != nil)
251
+ # is there some better way to express this?
252
+ !fit_to_width.nil? || !fit_to_height.nil?
228
253
  end
229
254
 
230
255
  # Serializes the page settings element.
231
256
  # @param [String] str
232
257
  # @return [String]
233
- def to_xml_string(str = '')
258
+ def to_xml_string(str = +'')
234
259
  serialized_tag('pageSetup', str)
235
260
  end
236
261
  end