caxlsx 4.0.0 → 4.4.1

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 (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +48 -12
  3. data/README.md +18 -9
  4. data/Rakefile +2 -9
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +6 -3
  7. data/lib/axlsx/content_type/content_type.rb +4 -4
  8. data/lib/axlsx/content_type/default.rb +4 -1
  9. data/lib/axlsx/content_type/override.rb +4 -1
  10. data/lib/axlsx/doc_props/app.rb +91 -24
  11. data/lib/axlsx/drawing/area_chart.rb +3 -3
  12. data/lib/axlsx/drawing/area_series.rb +10 -4
  13. data/lib/axlsx/drawing/ax_data_source.rb +1 -1
  14. data/lib/axlsx/drawing/axes.rb +1 -1
  15. data/lib/axlsx/drawing/axis.rb +25 -7
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -4
  17. data/lib/axlsx/drawing/bar_chart.rb +14 -4
  18. data/lib/axlsx/drawing/bar_series.rb +14 -5
  19. data/lib/axlsx/drawing/bubble_chart.rb +2 -2
  20. data/lib/axlsx/drawing/bubble_series.rb +2 -2
  21. data/lib/axlsx/drawing/cat_axis.rb +23 -8
  22. data/lib/axlsx/drawing/chart.rb +33 -8
  23. data/lib/axlsx/drawing/d_lbls.rb +9 -8
  24. data/lib/axlsx/drawing/drawing.rb +50 -49
  25. data/lib/axlsx/drawing/hyperlink.rb +13 -4
  26. data/lib/axlsx/drawing/line_3D_chart.rb +3 -3
  27. data/lib/axlsx/drawing/line_chart.rb +3 -3
  28. data/lib/axlsx/drawing/line_series.rb +10 -4
  29. data/lib/axlsx/drawing/marker.rb +19 -4
  30. data/lib/axlsx/drawing/num_val.rb +1 -1
  31. data/lib/axlsx/drawing/one_cell_anchor.rb +8 -2
  32. data/lib/axlsx/drawing/pic.rb +17 -8
  33. data/lib/axlsx/drawing/pie_3D_chart.rb +3 -3
  34. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  35. data/lib/axlsx/drawing/pie_series.rb +18 -6
  36. data/lib/axlsx/drawing/scaling.rb +18 -4
  37. data/lib/axlsx/drawing/scatter_chart.rb +2 -2
  38. data/lib/axlsx/drawing/scatter_series.rb +2 -2
  39. data/lib/axlsx/drawing/ser_axis.rb +11 -5
  40. data/lib/axlsx/drawing/series.rb +8 -2
  41. data/lib/axlsx/drawing/two_cell_anchor.rb +1 -1
  42. data/lib/axlsx/drawing/val_axis.rb +2 -2
  43. data/lib/axlsx/drawing/view_3D.rb +8 -2
  44. data/lib/axlsx/drawing/vml_shape.rb +1 -1
  45. data/lib/axlsx/package.rb +54 -21
  46. data/lib/axlsx/rels/relationship.rb +15 -5
  47. data/lib/axlsx/rels/relationships.rb +3 -3
  48. data/lib/axlsx/stylesheet/border.rb +12 -3
  49. data/lib/axlsx/stylesheet/border_pr.rb +16 -4
  50. data/lib/axlsx/stylesheet/cell_alignment.rb +39 -10
  51. data/lib/axlsx/stylesheet/cell_protection.rb +9 -2
  52. data/lib/axlsx/stylesheet/cell_style.rb +30 -7
  53. data/lib/axlsx/stylesheet/color.rb +10 -4
  54. data/lib/axlsx/stylesheet/dxf.rb +29 -6
  55. data/lib/axlsx/stylesheet/fill.rb +4 -1
  56. data/lib/axlsx/stylesheet/font.rb +59 -13
  57. data/lib/axlsx/stylesheet/gradient_fill.rb +9 -3
  58. data/lib/axlsx/stylesheet/gradient_stop.rb +9 -2
  59. data/lib/axlsx/stylesheet/num_fmt.rb +8 -2
  60. data/lib/axlsx/stylesheet/pattern_fill.rb +15 -3
  61. data/lib/axlsx/stylesheet/styles.rb +84 -43
  62. data/lib/axlsx/stylesheet/table_style.rb +15 -4
  63. data/lib/axlsx/stylesheet/table_style_element.rb +12 -3
  64. data/lib/axlsx/stylesheet/table_styles.rb +10 -3
  65. data/lib/axlsx/stylesheet/theme.rb +163 -0
  66. data/lib/axlsx/stylesheet/xf.rb +70 -16
  67. data/lib/axlsx/util/accessors.rb +9 -7
  68. data/lib/axlsx/util/buffered_zip_output_stream.rb +6 -2
  69. data/lib/axlsx/util/constants.rb +14 -2
  70. data/lib/axlsx/util/mime_type_utils.rb +72 -13
  71. data/lib/axlsx/util/serialized_attributes.rb +2 -2
  72. data/lib/axlsx/util/simple_typed_list.rb +26 -14
  73. data/lib/axlsx/util/storage.rb +4 -4
  74. data/lib/axlsx/util/uri_utils.rb +70 -0
  75. data/lib/axlsx/util/validators.rb +6 -6
  76. data/lib/axlsx/version.rb +1 -1
  77. data/lib/axlsx/workbook/defined_name.rb +2 -1
  78. data/lib/axlsx/workbook/defined_names.rb +1 -1
  79. data/lib/axlsx/workbook/shared_strings_table.rb +3 -3
  80. data/lib/axlsx/workbook/workbook.rb +87 -67
  81. data/lib/axlsx/workbook/workbook_view.rb +1 -1
  82. data/lib/axlsx/workbook/workbook_views.rb +1 -1
  83. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +4 -4
  84. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +5 -3
  85. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +4 -4
  86. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +1 -1
  87. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +2 -2
  88. data/lib/axlsx/workbook/worksheet/border_creator.rb +4 -4
  89. data/lib/axlsx/workbook/worksheet/cell.rb +40 -20
  90. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
  91. data/lib/axlsx/workbook/worksheet/cfvo.rb +8 -2
  92. data/lib/axlsx/workbook/worksheet/col.rb +23 -9
  93. data/lib/axlsx/workbook/worksheet/col_breaks.rb +1 -1
  94. data/lib/axlsx/workbook/worksheet/cols.rb +1 -1
  95. data/lib/axlsx/workbook/worksheet/comment.rb +2 -2
  96. data/lib/axlsx/workbook/worksheet/comments.rb +1 -1
  97. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +9 -3
  98. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +70 -15
  99. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +3 -3
  100. data/lib/axlsx/workbook/worksheet/data_validation.rb +53 -14
  101. data/lib/axlsx/workbook/worksheet/data_validations.rb +3 -3
  102. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +2 -2
  103. data/lib/axlsx/workbook/worksheet/dimension.rb +1 -1
  104. data/lib/axlsx/workbook/worksheet/header_footer.rb +1 -1
  105. data/lib/axlsx/workbook/worksheet/icon_set.rb +17 -5
  106. data/lib/axlsx/workbook/worksheet/merged_cells.rb +1 -1
  107. data/lib/axlsx/workbook/worksheet/outline_pr.rb +1 -1
  108. data/lib/axlsx/workbook/worksheet/page_margins.rb +30 -7
  109. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -2
  110. data/lib/axlsx/workbook/worksheet/page_setup.rb +32 -9
  111. data/lib/axlsx/workbook/worksheet/pane.rb +9 -2
  112. data/lib/axlsx/workbook/worksheet/pivot_table.rb +30 -6
  113. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +1 -1
  114. data/lib/axlsx/workbook/worksheet/print_options.rb +1 -0
  115. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +1 -1
  116. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +31 -11
  117. data/lib/axlsx/workbook/worksheet/row.rb +5 -2
  118. data/lib/axlsx/workbook/worksheet/row_breaks.rb +1 -1
  119. data/lib/axlsx/workbook/worksheet/selection.rb +8 -2
  120. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +1 -0
  121. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +1 -1
  122. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -1
  123. data/lib/axlsx/workbook/worksheet/sheet_view.rb +30 -9
  124. data/lib/axlsx/workbook/worksheet/table_style_info.rb +3 -2
  125. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  126. data/lib/axlsx/workbook/worksheet/worksheet.rb +28 -14
  127. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -4
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +3 -2
  130. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +2 -2
  131. data/lib/axlsx.rb +46 -30
  132. data/lib/caxlsx.rb +1 -1
  133. metadata +13 -52
@@ -1,67 +1,67 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
4
- require 'axlsx/workbook/worksheet/sheet_calc_pr'
5
- require 'axlsx/workbook/worksheet/auto_filter/auto_filter'
6
- require 'axlsx/workbook/worksheet/date_time_converter'
7
- require 'axlsx/workbook/worksheet/protected_range'
8
- require 'axlsx/workbook/worksheet/protected_ranges'
9
- require 'axlsx/workbook/worksheet/rich_text_run'
10
- require 'axlsx/workbook/worksheet/rich_text'
11
- require 'axlsx/workbook/worksheet/cell_serializer'
12
- require 'axlsx/workbook/worksheet/cell'
13
- require 'axlsx/workbook/worksheet/page_margins'
14
- require 'axlsx/workbook/worksheet/page_set_up_pr'
15
- require 'axlsx/workbook/worksheet/outline_pr'
16
- require 'axlsx/workbook/worksheet/page_setup'
17
- require 'axlsx/workbook/worksheet/header_footer'
18
- require 'axlsx/workbook/worksheet/print_options'
19
- require 'axlsx/workbook/worksheet/cfvo'
20
- require 'axlsx/workbook/worksheet/cfvos'
21
- require 'axlsx/workbook/worksheet/color_scale'
22
- require 'axlsx/workbook/worksheet/data_bar'
23
- require 'axlsx/workbook/worksheet/icon_set'
24
- require 'axlsx/workbook/worksheet/conditional_formatting'
25
- require 'axlsx/workbook/worksheet/conditional_formatting_rule'
26
- require 'axlsx/workbook/worksheet/conditional_formattings'
27
- require 'axlsx/workbook/worksheet/row'
28
- require 'axlsx/workbook/worksheet/col'
29
- require 'axlsx/workbook/worksheet/cols'
30
- require 'axlsx/workbook/worksheet/comments'
31
- require 'axlsx/workbook/worksheet/comment'
32
- require 'axlsx/workbook/worksheet/merged_cells'
33
- require 'axlsx/workbook/worksheet/sheet_protection'
34
- require 'axlsx/workbook/worksheet/sheet_pr'
35
- require 'axlsx/workbook/worksheet/dimension'
36
- require 'axlsx/workbook/worksheet/sheet_data'
37
- require 'axlsx/workbook/worksheet/worksheet_drawing'
38
- require 'axlsx/workbook/worksheet/worksheet_comments'
39
- require 'axlsx/workbook/worksheet/worksheet_hyperlink'
40
- require 'axlsx/workbook/worksheet/worksheet_hyperlinks'
41
- require 'axlsx/workbook/worksheet/break'
42
- require 'axlsx/workbook/worksheet/row_breaks'
43
- require 'axlsx/workbook/worksheet/col_breaks'
44
- require 'axlsx/workbook/workbook_view'
45
- require 'axlsx/workbook/workbook_views'
46
- require 'axlsx/workbook/worksheet/worksheet'
47
- require 'axlsx/workbook/shared_strings_table'
48
- require 'axlsx/workbook/defined_name'
49
- require 'axlsx/workbook/defined_names'
50
- require 'axlsx/workbook/worksheet/table_style_info'
51
- require 'axlsx/workbook/worksheet/table'
52
- require 'axlsx/workbook/worksheet/tables'
53
- require 'axlsx/workbook/worksheet/pivot_table_cache_definition'
54
- require 'axlsx/workbook/worksheet/pivot_table'
55
- require 'axlsx/workbook/worksheet/pivot_tables'
56
- require 'axlsx/workbook/worksheet/data_validation'
57
- require 'axlsx/workbook/worksheet/data_validations'
58
- require 'axlsx/workbook/worksheet/sheet_view'
59
- require 'axlsx/workbook/worksheet/sheet_format_pr'
60
- require 'axlsx/workbook/worksheet/pane'
61
- require 'axlsx/workbook/worksheet/selection'
4
+ require_relative 'worksheet/sheet_calc_pr'
5
+ require_relative 'worksheet/auto_filter/auto_filter'
6
+ require_relative 'worksheet/date_time_converter'
7
+ require_relative 'worksheet/protected_range'
8
+ require_relative 'worksheet/protected_ranges'
9
+ require_relative 'worksheet/rich_text_run'
10
+ require_relative 'worksheet/rich_text'
11
+ require_relative 'worksheet/cell_serializer'
12
+ require_relative 'worksheet/cell'
13
+ require_relative 'worksheet/page_margins'
14
+ require_relative 'worksheet/page_set_up_pr'
15
+ require_relative 'worksheet/outline_pr'
16
+ require_relative 'worksheet/page_setup'
17
+ require_relative 'worksheet/header_footer'
18
+ require_relative 'worksheet/print_options'
19
+ require_relative 'worksheet/cfvo'
20
+ require_relative 'worksheet/cfvos'
21
+ require_relative 'worksheet/color_scale'
22
+ require_relative 'worksheet/data_bar'
23
+ require_relative 'worksheet/icon_set'
24
+ require_relative 'worksheet/conditional_formatting'
25
+ require_relative 'worksheet/conditional_formatting_rule'
26
+ require_relative 'worksheet/conditional_formattings'
27
+ require_relative 'worksheet/row'
28
+ require_relative 'worksheet/col'
29
+ require_relative 'worksheet/cols'
30
+ require_relative 'worksheet/comments'
31
+ require_relative 'worksheet/comment'
32
+ require_relative 'worksheet/merged_cells'
33
+ require_relative 'worksheet/sheet_protection'
34
+ require_relative 'worksheet/sheet_pr'
35
+ require_relative 'worksheet/dimension'
36
+ require_relative 'worksheet/sheet_data'
37
+ require_relative 'worksheet/worksheet_drawing'
38
+ require_relative 'worksheet/worksheet_comments'
39
+ require_relative 'worksheet/worksheet_hyperlink'
40
+ require_relative 'worksheet/worksheet_hyperlinks'
41
+ require_relative 'worksheet/break'
42
+ require_relative 'worksheet/row_breaks'
43
+ require_relative 'worksheet/col_breaks'
44
+ require_relative 'workbook_view'
45
+ require_relative 'workbook_views'
46
+ require_relative 'worksheet/worksheet'
47
+ require_relative 'shared_strings_table'
48
+ require_relative 'defined_name'
49
+ require_relative 'defined_names'
50
+ require_relative 'worksheet/table_style_info'
51
+ require_relative 'worksheet/table'
52
+ require_relative 'worksheet/tables'
53
+ require_relative 'worksheet/pivot_table_cache_definition'
54
+ require_relative 'worksheet/pivot_table'
55
+ require_relative 'worksheet/pivot_tables'
56
+ require_relative 'worksheet/data_validation'
57
+ require_relative 'worksheet/data_validations'
58
+ require_relative 'worksheet/sheet_view'
59
+ require_relative 'worksheet/sheet_format_pr'
60
+ require_relative 'worksheet/pane'
61
+ require_relative 'worksheet/selection'
62
62
 
63
63
  # The Workbook class is an xlsx workbook that manages worksheets, charts, drawings and styles.
64
- # The following parts of the Office Open XML spreadsheet specification are not implimented in this version.
64
+ # The following parts of the Office Open XML spreadsheet specification are not implemented in this version.
65
65
  #
66
66
  # bookViews
67
67
  # calcPr
@@ -184,6 +184,12 @@ module Axlsx
184
184
  @styles
185
185
  end
186
186
 
187
+ # The theme associated with this workbook
188
+ # @return [Theme]
189
+ def theme
190
+ @theme ||= Theme.new
191
+ end
192
+
187
193
  # An array that holds all cells with styles
188
194
  # @return Set
189
195
  def styled_cells
@@ -217,7 +223,7 @@ module Axlsx
217
223
  # Indicates if the epoc date for serialization should be 1904. If false, 1900 is used.
218
224
  @@date1904 = false
219
225
 
220
- # A quick helper to retrive a worksheet by name
226
+ # A quick helper to retrieve a worksheet by name
221
227
  # @param [String] name The name of the sheet you are looking for
222
228
  # @return [Worksheet] The sheet found, or nil
223
229
  def sheet_by_name(name)
@@ -249,18 +255,28 @@ module Axlsx
249
255
 
250
256
  # Instance level access to the class variable 1904
251
257
  # @return [Boolean]
252
- def date1904() @@date1904; end
258
+ def date1904
259
+ @@date1904
260
+ end
253
261
 
254
262
  # see @date1904
255
- def date1904=(v) Axlsx.validate_boolean v; @@date1904 = v; end
263
+ def date1904=(v)
264
+ Axlsx.validate_boolean v
265
+ @@date1904 = v
266
+ end
256
267
 
257
268
  # Sets the date1904 attribute to the provided boolean
258
269
  # @return [Boolean]
259
- def self.date1904=(v) Axlsx.validate_boolean v; @@date1904 = v; end
270
+ def self.date1904=(v)
271
+ Axlsx.validate_boolean v
272
+ @@date1904 = v
273
+ end
260
274
 
261
275
  # retrieves the date1904 attribute
262
276
  # @return [Boolean]
263
- def self.date1904() @@date1904; end
277
+ def self.date1904
278
+ @@date1904
279
+ end
264
280
 
265
281
  # Whether to treat values starting with an equals sign as formulas or as literal strings.
266
282
  # Allowing user-generated data to be interpreted as formulas is a security risk.
@@ -280,10 +296,13 @@ module Axlsx
280
296
  # calculation. Thus the performance benefits of turning this off are
281
297
  # marginal unless you are creating a very large sheet.
282
298
  # @return [Boolean]
283
- def use_autowidth() @use_autowidth; end
299
+ attr_reader :use_autowidth
284
300
 
285
301
  # see @use_autowidth
286
- def use_autowidth=(v = true) Axlsx.validate_boolean v; @use_autowidth = v; end
302
+ def use_autowidth=(v = true)
303
+ Axlsx.validate_boolean v
304
+ @use_autowidth = v
305
+ end
287
306
 
288
307
  # Font size of bold fonts is multiplied with this
289
308
  # Used for automatic calculation of cell widths with bold text
@@ -360,6 +379,7 @@ module Axlsx
360
379
  r << Relationship.new(pivot_table.cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, format(PIVOT_TABLE_CACHE_DEFINITION_PN, index + 1))
361
380
  end
362
381
  r << Relationship.new(self, STYLES_R, STYLES_PN)
382
+ r << Relationship.new(self, THEME_R, THEME_PN)
363
383
  if use_shared_strings
364
384
  r << Relationship.new(self, SHARED_STRINGS_R, SHARED_STRINGS_PN)
365
385
  end
@@ -373,7 +393,7 @@ module Axlsx
373
393
  end
374
394
 
375
395
  # The xml:space attribute for the worksheet.
376
- # This determines how whitespace is handled withing the document.
396
+ # This determines how whitespace is handled within the document.
377
397
  # The most relevant part being whitespace in the cell text.
378
398
  # allowed values are :preserve and :default. Axlsx uses :preserve unless
379
399
  # you explicily set this to :default.
@@ -38,7 +38,7 @@ module Axlsx
38
38
  # @option [Boolean] show_horizontal_scroll Specifies a boolean value that indicates whether to display the horizontal scroll bar in the user interface.
39
39
  # @option [Boolean] show_vertical_scroll Specifies a boolean value that indicates whether to display the vertical scroll bar.
40
40
  # @option [Boolean] show_sheet_tabs Specifies a boolean value that indicates whether to display the sheet tabs in the user interface.
41
- # @option [Integer] tab_ratio Specifies ratio between the workbook tabs bar and the horizontal scroll bar.
41
+ # @option [Integer] tab_ratio Specifies the ratio between the workbook tabs bar and the horizontal scroll bar (from 0 to 1000, higher values mean more space for tabs). May only be supported on some clients.
42
42
  # @option [Integer] first_sheet Specifies the index to the first sheet in this book view.
43
43
  # @option [Integer] active_tab Specifies an unsignedInt that contains the index to the active sheet in this book view.
44
44
  # @option [Integer] x_window Specifies the X coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips.
@@ -5,7 +5,7 @@ module Axlsx
5
5
  class WorkbookViews < SimpleTypedList
6
6
  # creates the book views object
7
7
  def initialize
8
- super WorkbookView
8
+ super(WorkbookView)
9
9
  end
10
10
 
11
11
  # Serialize to xml
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'axlsx/workbook/worksheet/auto_filter/filter_column'
4
- require 'axlsx/workbook/worksheet/auto_filter/filters'
5
- require 'axlsx/workbook/worksheet/auto_filter/sort_state'
3
+ require_relative 'filter_column'
4
+ require_relative 'filters'
5
+ require_relative 'sort_state'
6
6
 
7
7
  module Axlsx
8
8
  # This class represents an auto filter range in a worksheet
@@ -80,7 +80,7 @@ module Axlsx
80
80
  condition.order == :asc ? index1 <=> index2 : index2 <=> index1
81
81
  end
82
82
 
83
- break unless comparison.zero?
83
+ break unless comparison == 0
84
84
  end
85
85
 
86
86
  comparison
@@ -10,7 +10,7 @@ module Axlsx
10
10
  include Axlsx::SerializedAttributes
11
11
 
12
12
  # Creates a new FilterColumn object
13
- # @note This class yeilds its filter object as that is where the vast majority of processing will be done
13
+ # @note This class yields its filter object as that is where the vast majority of processing will be done
14
14
  # @param [Integer|Cell] col_id The zero based index for the column to which this filter will be applied
15
15
  # @param [Symbol] filter_type The symbolized class name of the filter to apply to this column.
16
16
  # @param [Hash] options options for this object and the filter
@@ -43,7 +43,9 @@ module Axlsx
43
43
  # the filter button can be hidden, and not drawn.
44
44
  # @return [Boolean]
45
45
  def show_button
46
- @show_button ||= true
46
+ return @show_button if defined?(@show_button)
47
+
48
+ true
47
49
  end
48
50
 
49
51
  # Flag indicating whether the AutoFilter button for this column is hidden.
@@ -83,7 +85,7 @@ module Axlsx
83
85
  # @return [Boolean]
84
86
  def show_button=(show)
85
87
  Axlsx.validate_boolean show
86
- @show_botton = show
88
+ @show_button = show
87
89
  end
88
90
 
89
91
  # Serialize the object to xml
@@ -13,7 +13,7 @@ module Axlsx
13
13
  # @option [Boolean] blank @see blank
14
14
  # @option [String] calendar_type @see calendar_type
15
15
  # @option [Array] filter_items An array of values that will be used to create filter objects.
16
- # @option [Array] date_group_items An array of hases defining date group item filters to apply.
16
+ # @option [Array] date_group_items An array of hashes defining date group item filters to apply.
17
17
  # @note The recommended way to interact with filter objects is via AutoFilter#add_column
18
18
  # @example
19
19
  # ws.auto_filter.add_column(0, :filters, :blank => true, :calendar_type => 'japan', :filter_items => [100, 'a'])
@@ -36,12 +36,12 @@ module Axlsx
36
36
  # even when those dates are not using the same calendar system / date formatting.
37
37
  attr_reader :calendar_type
38
38
 
39
- # Tells us if the row of the cell provided should be filterd as it
39
+ # Tells us if the row of the cell provided should be filtered as it
40
40
  # does not meet any of the specified filter_items or
41
41
  # date_group_items restrictions.
42
42
  # @param [Cell] cell The cell to test against items
43
43
  # TODO implement this for date filters as well!
44
- def apply(cell)
44
+ def apply(cell) # rubocop:disable Naming/PredicateMethod
45
45
  return false unless cell
46
46
 
47
47
  filter_items.each do |filter|
@@ -138,7 +138,7 @@ module Axlsx
138
138
 
139
139
  # Creates a new DateGroupItem
140
140
  # @param [Hash] options A hash of options to use when
141
- # instanciating the object
141
+ # instantiating the object
142
142
  # @option [String] date_time_grouping the part of the date this
143
143
  # filter should apply for grouping
144
144
  # @option [Integer|String] year @see year
@@ -6,7 +6,7 @@ module Axlsx
6
6
  # Creates a new SortCondition object
7
7
  # @param [Integer] column_index Zero-based index indicating the AutoFilter column to which the sorting should be applied to
8
8
  # @param [Symbol] order The order the column should be sorted on, can only be :asc or :desc
9
- # @param [Array] custom_list An array containg a custom sorting list in order.
9
+ # @param [Array] custom_list An array containing a custom sorting list in order.
10
10
  def initialize(column_index:, order:, custom_list:)
11
11
  Axlsx.validate_int column_index
12
12
  @column_index = column_index
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'axlsx/workbook/worksheet/auto_filter/sort_condition'
3
+ require_relative 'sort_condition'
4
4
 
5
5
  module Axlsx
6
6
  # This class performs sorting on a range in a worksheet
@@ -21,7 +21,7 @@ module Axlsx
21
21
  # It requires a column_index for the sorting, descending and the custom order are optional.
22
22
  # @param [Integer] column_index Zero-based index indicating the AutoFilter column to which the sorting should be applied to
23
23
  # @param [Symbol] order The order the column should be sorted on, can only be :asc or :desc
24
- # @param [Array] custom_list An array containg a custom sorting list in order.
24
+ # @param [Array] custom_list An array containing a custom sorting list in order.
25
25
  # @return [SortCondition]
26
26
  def add_sort_condition(column_index:, order: :asc, custom_list: [])
27
27
  sort_conditions << SortCondition.new(column_index: column_index, order: order, custom_list: custom_list)
@@ -63,19 +63,19 @@ module Axlsx
63
63
  end
64
64
 
65
65
  def first_row
66
- @first_row ||= first_cell.scan(/\d+/).first
66
+ @first_row ||= first_cell[/\d+/]
67
67
  end
68
68
 
69
69
  def first_col
70
- @first_col ||= first_cell.scan(/\D+/).first
70
+ @first_col ||= first_cell[/\D+/]
71
71
  end
72
72
 
73
73
  def last_row
74
- @last_row ||= last_cell.scan(/\d+/).first
74
+ @last_row ||= last_cell[/\d+/]
75
75
  end
76
76
 
77
77
  def last_col
78
- @last_col ||= last_cell.scan(/\D+/).first
78
+ @last_col ||= last_cell[/\D+/]
79
79
  end
80
80
  end
81
81
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Axlsx
4
4
  # A cell in a worksheet.
5
- # Cell stores inforamation requried to serialize a single worksheet cell to xml. You must provde the Row that the cell belongs to and the cells value. The data type will automatically be determed if you do not specify the :type option. The default style will be applied if you do not supply the :style option. Changing the cell's type will recast the value to the type specified. Altering the cell's value via the property accessor will also automatically cast the provided value to the cell's type.
5
+ # Cell stores information required to serialize a single worksheet cell to xml. You must provide the Row that the cell belongs to and the cells value. The data type will automatically be determed if you do not specify the :type option. The default style will be applied if you do not supply the :style option. Changing the cell's type will recast the value to the type specified. Altering the cell's value via the property accessor will also automatically cast the provided value to the cell's type.
6
6
  # @note The recommended way to generate cells is via Worksheet#add_row
7
7
  #
8
8
  # @see Worksheet#add_row
@@ -41,7 +41,7 @@ module Axlsx
41
41
  self.type = type unless type == :string
42
42
 
43
43
  val = options.delete(:style)
44
- self.style = val unless val.nil? || val.zero?
44
+ self.style = val unless val.nil? || val == 0
45
45
  val = options.delete(:formula_value)
46
46
  self.formula_value = val unless val.nil?
47
47
  val = options.delete(:escape_formulas)
@@ -57,11 +57,11 @@ module Axlsx
57
57
  # you need to set this.
58
58
  attr_accessor :formula_value
59
59
 
60
- # An array of available inline styes.
60
+ # An array of available inline styles.
61
61
  # TODO change this to a hash where each key defines attr name and validator (and any info the validator requires)
62
- # then move it out to a module so we can re-use in in other classes.
62
+ # then move it out to a module so we can reuse in in other classes.
63
63
  # needs to define bla=(v) and bla methods on the class that hook into a
64
- # set_attr method that kicks the suplied validator and updates the instance_variable
64
+ # set_attr method that kicks the supplied validator and updates the instance_variable
65
65
  # for the key
66
66
  INLINE_STYLES = [:value, :type, :font_name, :charset,
67
67
  :family, :b, :i, :strike, :outline,
@@ -166,7 +166,7 @@ module Axlsx
166
166
 
167
167
  # Indicates that the cell has one or more of the custom cell styles applied.
168
168
  # @return [Boolean]
169
- def is_text_run? # rubocop:disable Naming/PredicateName
169
+ def is_text_run? # rubocop:disable Naming/PredicatePrefix
170
170
  defined?(@is_text_run) && @is_text_run && !contains_rich_text?
171
171
  end
172
172
 
@@ -189,7 +189,9 @@ module Axlsx
189
189
  attr_reader :font_name
190
190
 
191
191
  # @see font_name
192
- def font_name=(v) set_run_style :validate_string, :font_name, v; end
192
+ def font_name=(v)
193
+ set_run_style :validate_string, :font_name, v
194
+ end
193
195
 
194
196
  # The inline charset property for the cell
195
197
  # As far as I can tell, this is pretty much ignored. However, based on the spec it should be one of the following:
@@ -216,7 +218,9 @@ module Axlsx
216
218
  attr_reader :charset
217
219
 
218
220
  # @see charset
219
- def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end
221
+ def charset=(v)
222
+ set_run_style :validate_unsigned_int, :charset, v
223
+ end
220
224
 
221
225
  # The inline family property for the cell
222
226
  # @return [Integer]
@@ -237,49 +241,63 @@ module Axlsx
237
241
  attr_reader :b
238
242
 
239
243
  # @see b
240
- def b=(v) set_run_style :validate_boolean, :b, v; end
244
+ def b=(v)
245
+ set_run_style :validate_boolean, :b, v
246
+ end
241
247
 
242
248
  # The inline italic property for the cell
243
249
  # @return [Boolean]
244
250
  attr_reader :i
245
251
 
246
252
  # @see i
247
- def i=(v) set_run_style :validate_boolean, :i, v; end
253
+ def i=(v)
254
+ set_run_style :validate_boolean, :i, v
255
+ end
248
256
 
249
257
  # The inline strike property for the cell
250
258
  # @return [Boolean]
251
259
  attr_reader :strike
252
260
 
253
261
  # @see strike
254
- def strike=(v) set_run_style :validate_boolean, :strike, v; end
262
+ def strike=(v)
263
+ set_run_style :validate_boolean, :strike, v
264
+ end
255
265
 
256
266
  # The inline outline property for the cell
257
267
  # @return [Boolean]
258
268
  attr_reader :outline
259
269
 
260
270
  # @see outline
261
- def outline=(v) set_run_style :validate_boolean, :outline, v; end
271
+ def outline=(v)
272
+ set_run_style :validate_boolean, :outline, v
273
+ end
262
274
 
263
275
  # The inline shadow property for the cell
264
276
  # @return [Boolean]
265
277
  attr_reader :shadow
266
278
 
267
279
  # @see shadow
268
- def shadow=(v) set_run_style :validate_boolean, :shadow, v; end
280
+ def shadow=(v)
281
+ set_run_style :validate_boolean, :shadow, v
282
+ end
269
283
 
270
284
  # The inline condense property for the cell
271
285
  # @return [Boolean]
272
286
  attr_reader :condense
273
287
 
274
288
  # @see condense
275
- def condense=(v) set_run_style :validate_boolean, :condense, v; end
289
+ def condense=(v)
290
+ set_run_style :validate_boolean, :condense, v
291
+ end
276
292
 
277
293
  # The inline extend property for the cell
278
294
  # @return [Boolean]
279
295
  attr_reader :extend
280
296
 
281
297
  # @see extend
282
- def extend=(v) set_run_style :validate_boolean, :extend, v; end
298
+ def extend=(v)
299
+ set_run_style :validate_boolean, :extend, v
300
+ end
283
301
 
284
302
  # The inline underline property for the cell.
285
303
  # It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting
@@ -307,7 +325,9 @@ module Axlsx
307
325
  attr_reader :sz
308
326
 
309
327
  # @see sz
310
- def sz=(v) set_run_style :validate_unsigned_int, :sz, v; end
328
+ def sz=(v)
329
+ set_run_style :validate_unsigned_int, :sz, v
330
+ end
311
331
 
312
332
  # The inline vertical alignment property for the cell
313
333
  # this must be one of [:baseline, :subscript, :superscript]
@@ -390,13 +410,13 @@ module Axlsx
390
410
  CellSerializer.to_xml_string r_index, c_index, self, str
391
411
  end
392
412
 
393
- def is_formula? # rubocop:disable Naming/PredicateName
413
+ def is_formula? # rubocop:disable Naming/PredicatePrefix
394
414
  return false if escape_formulas
395
415
 
396
416
  type == :string && @value.to_s.start_with?(FORMULA_PREFIX)
397
417
  end
398
418
 
399
- def is_array_formula? # rubocop:disable Naming/PredicateName
419
+ def is_array_formula? # rubocop:disable Naming/PredicatePrefix
400
420
  return false if escape_formulas
401
421
 
402
422
  type == :string &&
@@ -529,14 +549,14 @@ module Axlsx
529
549
 
530
550
  case type
531
551
  when :date
532
- self.style = STYLE_DATE if style.zero?
552
+ self.style = STYLE_DATE if style == 0
533
553
  if !v.is_a?(Date) && v.respond_to?(:to_date)
534
554
  v.to_date
535
555
  else
536
556
  v
537
557
  end
538
558
  when :time
539
- self.style = STYLE_DATE if style.zero?
559
+ self.style = STYLE_DATE if style == 0
540
560
  if !v.is_a?(Time) && v.respond_to?(:to_time)
541
561
  v.to_time
542
562
  else
@@ -7,7 +7,7 @@ module Axlsx
7
7
  # Calls the proper serialization method based on type.
8
8
  # @param [Integer] row_index The index of the cell's row
9
9
  # @param [Integer] column_index The index of the cell's column
10
- # @param [String] str The string to apend serialization to.
10
+ # @param [String] str The string to append serialization to.
11
11
  # @return [String]
12
12
  def to_xml_string(row_index, column_index, cell, str = +'')
13
13
  str << '<c r="'
@@ -40,10 +40,16 @@ module Axlsx
40
40
  attr_reader :val
41
41
 
42
42
  # @see type
43
- def type=(v); Axlsx.validate_conditional_formatting_value_object_type(v); @type = v end
43
+ def type=(v)
44
+ Axlsx.validate_conditional_formatting_value_object_type(v)
45
+ @type = v
46
+ end
44
47
 
45
48
  # @see gte
46
- def gte=(v); Axlsx.validate_boolean(v); @gte = v end
49
+ def gte=(v)
50
+ Axlsx.validate_boolean(v)
51
+ @gte = v
52
+ end
47
53
 
48
54
  # @see val
49
55
  def val=(v)
@@ -9,6 +9,7 @@ module Axlsx
9
9
 
10
10
  include Axlsx::OptionsParser
11
11
  include Axlsx::SerializedAttributes
12
+
12
13
  # Create a new Col objects
13
14
  # @param min First column affected by this 'column info' record.
14
15
  # @param max Last column affected by this 'column info' record.
@@ -110,7 +111,7 @@ module Axlsx
110
111
  def width=(v)
111
112
  # Removing this validation make a 10% difference in performance
112
113
  # as it is called EVERY TIME A CELL IS ADDED - the proper solution
113
- # is to only set this if a calculated value is greated than the
114
+ # is to only set this if a calculated value is greater than the
114
115
  # current @width value.
115
116
  # TODO!!!
116
117
  # Axlsx.validate_unsigned_numeric(v) unless v == nil
@@ -121,17 +122,30 @@ module Axlsx
121
122
  # updates the width for this col based on the cells autowidth and
122
123
  # an optionally specified fixed width
123
124
  # @param [Cell] cell The cell to use in updating this col's width
124
- # @param [Integer] fixed_width If this is specified the width is set
125
- # to this value and the cell's attributes are ignored.
125
+ # @param [Numeric, :auto, :ignore, nil] fixed_width Decides how the width
126
+ # of the cell should be updated. If this is specified as as Numeric the
127
+ # width is set to this value and the cell's attributes are ignored. If set
128
+ # to `nil` or `:auto` and `use_autowidth` is true, it uses the autowidth of
129
+ # the cell. If set to `:ignore`, the cell's width is not changed. In any
130
+ # case the col's width is set to the new value only if the current width is
131
+ # smaller than the new one, so that the largest width of all cells in this
132
+ # column is used.
126
133
  # @param [Boolean] use_autowidth If this is false, the cell's
127
134
  # autowidth value will be ignored.
128
135
  def update_width(cell, fixed_width = nil, use_autowidth = true)
129
- if fixed_width.is_a? Numeric
130
- self.width = fixed_width
131
- elsif use_autowidth
132
- cell_width = cell.autowidth
133
- self.width = cell_width unless (width || 0) > (cell_width || 0)
134
- end
136
+ cell_width =
137
+ case fixed_width
138
+ when Numeric
139
+ fixed_width
140
+ when nil, :auto
141
+ cell.autowidth if use_autowidth
142
+ when :ignore
143
+ nil
144
+ else
145
+ raise ArgumentError, "fixed_with must be a Numeric, :auto, :ignore or nil, but is '#{fixed_width.inspect}'"
146
+ end
147
+
148
+ self.width = cell_width unless (width || 0) > (cell_width || 0)
135
149
  end
136
150
 
137
151
  # Serialize this columns data to an xml string
@@ -7,7 +7,7 @@ module Axlsx
7
7
  class ColBreaks < SimpleTypedList
8
8
  # Instantiates a new list restricted to Break types
9
9
  def initialize
10
- super Break
10
+ super(Break)
11
11
  end
12
12
 
13
13
  # A column break specific helper for adding a break.
@@ -7,7 +7,7 @@ module Axlsx
7
7
  def initialize(worksheet)
8
8
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
9
9
 
10
- super Col
10
+ super(Col)
11
11
  @worksheet = worksheet
12
12
  end
13
13