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,9 +1,8 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # The Col class defines column attributes for columns in sheets.
5
5
  class Col
6
-
7
6
  # Maximum column width limit in MS Excel is 255 characters
8
7
  # https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
9
8
  MAX_WIDTH = 255
@@ -19,7 +18,7 @@ module Axlsx
19
18
  # @option options [Boolean] phonetic see Col#phonetic
20
19
  # @option options [Integer] style see Col#style
21
20
  # @option options [Numeric] width see Col#width
22
- def initialize(min, max, options={})
21
+ def initialize(min, max, options = {})
23
22
  Axlsx.validate_unsigned_int(max)
24
23
  Axlsx.validate_unsigned_int(min)
25
24
  @min = min
@@ -89,7 +88,8 @@ module Axlsx
89
88
  # @see Col#outline
90
89
  def outline_level=(v)
91
90
  Axlsx.validate_unsigned_numeric(v)
92
- raise ArgumentError, 'outlineLevel must be between 0 and 7' unless 0 <= v && v <= 7
91
+ raise ArgumentError, 'outlineLevel must be between 0 and 7' unless v >= 0 && v <= 7
92
+
93
93
  @outline_level = v
94
94
  end
95
95
  alias :outlineLevel= :outline_level=
@@ -106,15 +106,15 @@ module Axlsx
106
106
  @style = v
107
107
  end
108
108
 
109
- # @see Col#width
109
+ # @see Col#width
110
110
  def width=(v)
111
111
  # Removing this validation make a 10% difference in performance
112
112
  # as it is called EVERY TIME A CELL IS ADDED - the proper solution
113
113
  # is to only set this if a calculated value is greated than the
114
114
  # current @width value.
115
115
  # TODO!!!
116
- #Axlsx.validate_unsigned_numeric(v) unless v == nil
117
- @custom_width = @best_fit = v != nil
116
+ # Axlsx.validate_unsigned_numeric(v) unless v == nil
117
+ @custom_width = @best_fit = !v.nil?
118
118
  @width = v.nil? ? v : [v, MAX_WIDTH].min
119
119
  end
120
120
 
@@ -137,9 +137,8 @@ module Axlsx
137
137
  # Serialize this columns data to an xml string
138
138
  # @param [String] str
139
139
  # @return [String]
140
- def to_xml_string(str = '')
140
+ def to_xml_string(str = +'')
141
141
  serialized_tag('col', str)
142
142
  end
143
-
144
143
  end
145
144
  end
@@ -1,10 +1,10 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # A collection of Brake objects.
4
- # Please do not use this class directly. Instead use
5
+ # Please do not use this class directly. Instead use
5
6
  # Worksheet#add_break
6
7
  class ColBreaks < SimpleTypedList
7
-
8
8
  # Instantiates a new list restricted to Break types
9
9
  def initialize
10
10
  super Break
@@ -12,11 +12,11 @@ module Axlsx
12
12
 
13
13
  # A column break specific helper for adding a break.
14
14
  # @param [Hash] options A list of options to pass into the Break object
15
- # The max and man options are fixed, however any other valid option for
15
+ # The max and man options are fixed, however any other valid option for
16
16
  # Break will be passed to the created break object.
17
17
  # @see Break
18
18
  def add_break(options)
19
- self << Break.new(options.merge(:max => 1048575, :man => true))
19
+ self << Break.new(options.merge(max: 1048575, man: true))
20
20
  last
21
21
  end
22
22
 
@@ -25,9 +25,10 @@ module Axlsx
25
25
  # <colBreaks count="1" manualBreakCount="1">
26
26
  # <brk id="3" max="1048575" man="1"/>
27
27
  # </colBreaks>
28
- def to_xml_string(str='')
28
+ def to_xml_string(str = +'')
29
29
  return if empty?
30
- str << ('<colBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">')
30
+
31
+ str << '<colBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">'
31
32
  each { |brk| brk.to_xml_string(str) }
32
33
  str << '</colBreaks>'
33
34
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Conditional Format Rule color scale object
3
5
  # Describes a gradated color scale in this conditional formatting rule.
@@ -6,14 +8,12 @@ module Axlsx
6
8
  # @see Worksheet#add_conditional_formatting
7
9
  # @see ConditionalFormattingRule#initialize
8
10
  class ColorScale
9
-
10
11
  class << self
11
-
12
12
  # These are the default conditional formatting value objects
13
13
  # that define a two tone color gradient.
14
14
  def default_cfvos
15
- [{:type => :min, :val => 0, :color => 'FFFF7128'},
16
- {:type => :max, :val => 0, :color => 'FFFFEF9C'}]
15
+ [{ type: :min, val: 0, color: 'FFFF7128' },
16
+ { type: :max, val: 0, color: 'FFFFEF9C' }]
17
17
  end
18
18
 
19
19
  # A builder for two tone color gradient
@@ -22,18 +22,18 @@ module Axlsx
22
22
  # color_scale = Axlsx::ColorScale.two_tone
23
23
  # @see examples/example.rb conditional formatting examples.
24
24
  def two_tone
25
- self.new
25
+ new
26
26
  end
27
27
 
28
28
  # A builder for three tone color gradient
29
29
  # @example
30
30
  # #this creates a three tone color scale
31
- # color_scale = Axlsx::ColorScale.three_tone
31
+ # color_scale = Axlsx::ColorScale.three_tone
32
32
  # @see examples/example.rb conditional formatting examples.
33
33
  def three_tone
34
- self.new({:type => :min, :val => 0, :color => 'FFF8696B'},
35
- {:type => :percent, :val => '50', :color => 'FFFFEB84'},
36
- {:type => :max, :val => 0, :color => 'FF63BE7B'})
34
+ new({ type: :min, val: 0, color: 'FFF8696B' },
35
+ { type: :percent, val: '50', color: 'FFFFEB84' },
36
+ { type: :max, val: 0, color: 'FF63BE7B' })
37
37
  end
38
38
  end
39
39
  # A simple typed list of cfvos
@@ -67,17 +67,16 @@ module Axlsx
67
67
  # @option [Symbol] type The type of cfvo you to add
68
68
  # @option [Any] val The value of the cfvo to add
69
69
  # @option [String] The rgb color for the cfvo
70
- def add(options={})
71
- value_objects << Cfvo.new(:type => options[:type] || :min, :val => options[:val] || 0)
72
- colors << Color.new(:rgb => options[:color] || "FF000000")
73
- {:cfvo => value_objects.last, :color => colors.last}
70
+ def add(options = {})
71
+ value_objects << Cfvo.new(type: options[:type] || :min, val: options[:val] || 0)
72
+ colors << Color.new(rgb: options[:color] || "FF000000")
73
+ { cfvo: value_objects.last, color: colors.last }
74
74
  end
75
75
 
76
-
77
76
  # removes the cfvo and color pair at the index specified.
78
77
  # @param [Integer] index The index of the cfvo and color object to delete
79
78
  # @note you cannot remove the first two cfvo and color pairs
80
- def delete_at(index=2)
79
+ def delete_at(index = 2)
81
80
  value_objects.delete_at index
82
81
  colors.delete_at index
83
82
  end
@@ -85,7 +84,7 @@ module Axlsx
85
84
  # Serialize this color_scale object data to an xml string
86
85
  # @param [String] str
87
86
  # @return [String]
88
- def to_xml_string(str = '')
87
+ def to_xml_string(str = +'')
89
88
  str << '<colorScale>'
90
89
  value_objects.to_xml_string(str)
91
90
  colors.each { |color| color.to_xml_string(str) }
@@ -93,6 +92,7 @@ module Axlsx
93
92
  end
94
93
 
95
94
  private
95
+
96
96
  # There has got to be cleaner way of merging these arrays.
97
97
  def initialize_default_cfvos(user_cfvos)
98
98
  defaults = self.class.default_cfvos
@@ -1,11 +1,12 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # The cols class manages the col object used to manage column widths.
4
5
  # This is where the magic happens with autowidth
5
6
  class Cols < SimpleTypedList
6
-
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
11
  @worksheet = worksheet
11
12
  end
@@ -13,11 +14,12 @@ module Axlsx
13
14
  # Serialize the Cols object
14
15
  # @param [String] str
15
16
  # @return [String]
16
- def to_xml_string(str = '')
17
- return if empty?
18
- str << '<cols>'
19
- each { |item| item.to_xml_string(str) }
20
- str << '</cols>'
17
+ def to_xml_string(str = +'')
18
+ return if empty?
19
+
20
+ str << '<cols>'
21
+ each { |item| item.to_xml_string(str) }
22
+ str << '</cols>'
21
23
  end
22
24
  end
23
25
  end
@@ -1,8 +1,8 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # A comment is the text data for a comment
4
5
  class Comment
5
-
6
6
  include Axlsx::OptionsParser
7
7
  include Axlsx::Accessors
8
8
 
@@ -13,8 +13,9 @@ module Axlsx
13
13
  # @option [String] text The text for the comment
14
14
  # @option [String] ref The refence (e.g. 'A3' where this comment will be anchored.
15
15
  # @option [Boolean] visible This controls the visiblity of the associated vml_shape.
16
- def initialize(comments, options={})
16
+ def initialize(comments, options = {})
17
17
  raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
18
+
18
19
  @visible = true
19
20
  @comments = comments
20
21
  parse_options options
@@ -60,17 +61,17 @@ module Axlsx
60
61
  # serialize the object
61
62
  # @param [String] str
62
63
  # @return [String]
63
- def to_xml_string(str = "")
64
+ def to_xml_string(str = +'')
64
65
  author = @comments.authors[author_index]
65
- str << ('<comment ref="' << ref << '" authorId="' << author_index.to_s << '">')
66
+ str << '<comment ref="' << ref << '" authorId="' << author_index.to_s << '">'
66
67
  str << '<text>'
67
68
  unless author.to_s == ""
68
69
  str << '<r><rPr><b/><color indexed="81"/></rPr>'
69
- str << ("<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>")
70
+ str << "<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>"
70
71
  end
71
72
  str << '<r>'
72
73
  str << '<rPr><color indexed="81"/></rPr>'
73
- str << ('<t>' << ::CGI.escapeHTML(text) << '</t></r></text>')
74
+ str << '<t>' << ::CGI.escapeHTML(text) << '</t></r></text>'
74
75
  str << '</comment>'
75
76
  end
76
77
 
@@ -79,12 +80,12 @@ module Axlsx
79
80
  # initialize the vml shape based on this comment's ref/position in the worksheet.
80
81
  # by default, all columns are 5 columns wide and 5 rows high
81
82
  def initialize_vml_shape
82
- pos = Axlsx::name_to_indices(ref)
83
- @vml_shape = VmlShape.new(:row => pos[1], :column => pos[0], :visible => @visible) do |vml|
83
+ pos = Axlsx.name_to_indices(ref)
84
+ @vml_shape = VmlShape.new(row: pos[1], column: pos[0], visible: @visible) do |vml|
84
85
  vml.left_column = vml.column
85
- vml.right_column = vml.column + 2
86
+ vml.right_column = vml.column + 2
86
87
  vml.top_row = vml.row
87
- vml.bottom_row = vml.row + 4
88
+ vml.bottom_row = vml.row + 4
88
89
  end
89
90
  end
90
91
  end
@@ -1,9 +1,8 @@
1
- # -*- coding: utf-8 -*-
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # Comments is a collection of Comment objects for a worksheet
5
5
  class Comments < SimpleTypedList
6
-
7
6
  # the vml_drawing that holds the shapes for comments
8
7
  # @return [VmlDrawing]
9
8
  attr_reader :vml_drawing
@@ -21,13 +20,14 @@ module Axlsx
21
20
  # The part name for this object
22
21
  # @return [String]
23
22
  def pn
24
- "#{COMMENT_PN % (index+1)}"
23
+ format(COMMENT_PN, index + 1)
25
24
  end
26
25
 
27
26
  # Creates a new Comments object
28
27
  # @param [Worksheet] worksheet The sheet that these comments belong to.
29
28
  def initialize(worksheet)
30
29
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
30
+
31
31
  super(Comment)
32
32
  @worksheet = worksheet
33
33
  @vml_drawing = VmlDrawing.new(self)
@@ -38,10 +38,11 @@ module Axlsx
38
38
  # @option options [String] author The name of the author for this comment
39
39
  # @option options [String] text The text for this comment
40
40
  # @option options [Stirng|Cell] ref The cell that this comment is attached to.
41
- def add_comment(options={})
41
+ def add_comment(options = {})
42
42
  raise ArgumentError, "Comment require an author" unless options[:author]
43
43
  raise ArgumentError, "Comment requires text" unless options[:text]
44
44
  raise ArgumentError, "Comment requires ref" unless options[:ref]
45
+
45
46
  self << Comment.new(self, options)
46
47
  yield last if block_given?
47
48
  last
@@ -63,20 +64,17 @@ module Axlsx
63
64
  # serialize the object
64
65
  # @param [String] str
65
66
  # @return [String]
66
- def to_xml_string(str="")
67
+ def to_xml_string(str = +'')
67
68
  str << '<?xml version="1.0" encoding="UTF-8"?>'
68
- str << ('<comments xmlns="' << XML_NS << '"><authors>')
69
- authors.each do |author|
70
- str << ('<author>' << author.to_s << '</author>')
69
+ str << '<comments xmlns="' << XML_NS << '"><authors>'
70
+ authors.each do |author|
71
+ str << '<author>' << author.to_s << '</author>'
71
72
  end
72
73
  str << '</authors><commentList>'
73
74
  each do |comment|
74
75
  comment.to_xml_string str
75
76
  end
76
77
  str << '</commentList></comments>'
77
-
78
78
  end
79
-
80
79
  end
81
-
82
80
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Conditional formatting allows styling of ranges based on functions
3
5
  #
@@ -5,13 +7,12 @@ module Axlsx
5
7
  # @see Worksheet#add_conditional_formatting
6
8
  # @see ConditionalFormattingRule
7
9
  class ConditionalFormatting
10
+ include Axlsx::OptionsParser
8
11
 
9
- include Axlsx::OptionsParser
10
-
11
12
  # Creates a new {ConditionalFormatting} object
12
13
  # @option options [Array] rules The rules to apply
13
14
  # @option options [String] sqref The range to apply the rules to
14
- def initialize(options={})
15
+ def initialize(options = {})
15
16
  @rules = []
16
17
  parse_options options
17
18
  end
@@ -28,7 +29,7 @@ module Axlsx
28
29
  # @return [Array]
29
30
  attr_reader :rules
30
31
 
31
- # Add Conditional Formatting Rules to this object. Rules can either
32
+ # Add Conditional Formatting Rules to this object. Rules can either
32
33
  # be already created {ConditionalFormattingRule} elements or
33
34
  # hashes of options for automatic creation. If rules is a hash
34
35
  # instead of an array, assume only one rule being added.
@@ -62,7 +63,7 @@ module Axlsx
62
63
  # @see rules
63
64
  def rules=(v); @rules = v end
64
65
  # @see sqref
65
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
66
+ def sqref=(v); Axlsx.validate_string(v); @sqref = v end
66
67
 
67
68
  # Serializes the conditional formatting element
68
69
  # @example Conditional Formatting XML looks like:
@@ -73,9 +74,12 @@ module Axlsx
73
74
  # </conditionalFormatting>
74
75
  # @param [String] str
75
76
  # @return [String]
76
- def to_xml_string(str = '')
77
- str << ('<conditionalFormatting sqref="' << sqref << '">')
78
- str << rules.collect{ |rule| rule.to_xml_string }.join(' ')
77
+ def to_xml_string(str = +'')
78
+ str << '<conditionalFormatting sqref="' << sqref << '">'
79
+ rules.each_with_index do |rule, index|
80
+ str << ' ' unless index.zero?
81
+ rule.to_xml_string(str)
82
+ end
79
83
  str << '</conditionalFormatting>'
80
84
  end
81
85
  end
@@ -1,4 +1,5 @@
1
- # -*- coding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # Conditional formatting rules specify formulas whose evaluations
4
5
  # format cells
@@ -7,7 +8,6 @@ module Axlsx
7
8
  # @see Worksheet#add_conditional_formatting
8
9
  # @see ConditionalFormattingRule#initialize
9
10
  class ConditionalFormattingRule
10
-
11
11
  include Axlsx::OptionsParser
12
12
  include Axlsx::SerializedAttributes
13
13
 
@@ -26,7 +26,7 @@ module Axlsx
26
26
  # @option options [Boolean] stopIfTrue Stop evaluating rules after this rule matches
27
27
  # @option options [Symbol] timePeriod The time period in a date occuring... rule
28
28
  # @option options [String] formula The formula to match against in i.e. an equal rule. Use a [minimum, maximum] array for cellIs between/notBetween conditionals.
29
- def initialize(options={})
29
+ def initialize(options = {})
30
30
  @color_scale = @data_bar = @icon_set = @formula = nil
31
31
  parse_options options
32
32
  end
@@ -133,7 +133,6 @@ module Axlsx
133
133
  # thisMonth, lastMonth, nextMonth, thisWeek, lastWeek, nextWeek
134
134
  attr_reader :timePeriod
135
135
 
136
-
137
136
  # colorScale (Color Scale)
138
137
  # The color scale to apply to this conditional formatting
139
138
  # @return [ColorScale]
@@ -156,33 +155,33 @@ module Axlsx
156
155
  end
157
156
 
158
157
  # @see type
159
- def type=(v); Axlsx::validate_conditional_formatting_type(v); @type = v end
158
+ def type=(v); Axlsx.validate_conditional_formatting_type(v); @type = v end
160
159
  # @see aboveAverage
161
- def aboveAverage=(v); Axlsx::validate_boolean(v); @aboveAverage = v end
160
+ def aboveAverage=(v); Axlsx.validate_boolean(v); @aboveAverage = v end
162
161
  # @see bottom
163
- def bottom=(v); Axlsx::validate_boolean(v); @bottom = v end
162
+ def bottom=(v); Axlsx.validate_boolean(v); @bottom = v end
164
163
  # @see dxfId
165
- def dxfId=(v); Axlsx::validate_unsigned_numeric(v); @dxfId = v end
164
+ def dxfId=(v); Axlsx.validate_unsigned_numeric(v); @dxfId = v end
166
165
  # @see equalAverage
167
- def equalAverage=(v); Axlsx::validate_boolean(v); @equalAverage = v end
166
+ def equalAverage=(v); Axlsx.validate_boolean(v); @equalAverage = v end
168
167
  # @see priority
169
- def priority=(v); Axlsx::validate_unsigned_numeric(v); @priority = v end
168
+ def priority=(v); Axlsx.validate_unsigned_numeric(v); @priority = v end
170
169
  # @see operator
171
- def operator=(v); Axlsx::validate_conditional_formatting_operator(v); @operator = v end
170
+ def operator=(v); Axlsx.validate_conditional_formatting_operator(v); @operator = v end
172
171
  # @see text
173
- def text=(v); Axlsx::validate_string(v); @text = v end
172
+ def text=(v); Axlsx.validate_string(v); @text = v end
174
173
  # @see percent
175
- def percent=(v); Axlsx::validate_boolean(v); @percent = v end
174
+ def percent=(v); Axlsx.validate_boolean(v); @percent = v end
176
175
  # @see rank
177
- def rank=(v); Axlsx::validate_unsigned_numeric(v); @rank = v end
176
+ def rank=(v); Axlsx.validate_unsigned_numeric(v); @rank = v end
178
177
  # @see stdDev
179
- def stdDev=(v); Axlsx::validate_unsigned_numeric(v); @stdDev = v end
178
+ def stdDev=(v); Axlsx.validate_unsigned_numeric(v); @stdDev = v end
180
179
  # @see stopIfTrue
181
- def stopIfTrue=(v); Axlsx::validate_boolean(v); @stopIfTrue = v end
180
+ def stopIfTrue=(v); Axlsx.validate_boolean(v); @stopIfTrue = v end
182
181
  # @see timePeriod
183
- def timePeriod=(v); Axlsx::validate_time_period_type(v); @timePeriod = v end
182
+ def timePeriod=(v); Axlsx.validate_time_period_type(v); @timePeriod = v end
184
183
  # @see formula
185
- def formula=(v); [*v].each {|x| Axlsx::validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
184
+ def formula=(v); [*v].each { |x| Axlsx.validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
186
185
 
187
186
  # @see color_scale
188
187
  def color_scale=(v)
@@ -202,15 +201,14 @@ module Axlsx
202
201
  @icon_set = v
203
202
  end
204
203
 
205
-
206
204
  # Serializes the conditional formatting rule
207
205
  # @param [String] str
208
206
  # @return [String]
209
- def to_xml_string(str = '')
207
+ def to_xml_string(str = +'')
210
208
  str << '<cfRule '
211
209
  serialized_attributes str
212
210
  str << '>'
213
- str << ('<formula>' << [*self.formula].join('</formula><formula>') << '</formula>') if @formula
211
+ str << '<formula>' << [*formula].join('</formula><formula>') << '</formula>' if @formula
214
212
  @color_scale.to_xml_string(str) if @color_scale && @type == :colorScale
215
213
  @data_bar.to_xml_string(str) if @data_bar && @type == :dataBar
216
214
  @icon_set.to_xml_string(str) if @icon_set && @type == :iconSet
@@ -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 ConditionalFormattings < 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 ConditionalFormatting
10
11
  @worksheet = worksheet
11
12
  end
@@ -15,11 +16,10 @@ 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
  each { |item| item.to_xml_string(str) }
21
23
  end
22
24
  end
23
-
24
25
  end
25
-
@@ -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.
@@ -6,15 +8,14 @@ module Axlsx
6
8
  # @see Worksheet#add_conditional_formatting
7
9
  # @see ConditionalFormattingRule#initialize
8
10
  class DataBar
9
-
10
11
  include Axlsx::OptionsParser
11
12
  include Axlsx::SerializedAttributes
12
13
 
13
14
  class << self
14
15
  # This differs from ColorScale. There must be exactly two cfvos one color
15
16
  def default_cfvos
16
- [{:type => :min, :val => "0"},
17
- {:type => :max, :val => "0"}]
17
+ [{ type: :min, val: "0" },
18
+ { type: :max, val: "0" }]
18
19
  end
19
20
  end
20
21
 
@@ -37,7 +38,7 @@ module Axlsx
37
38
  serializable_attributes :min_length, :max_length, :show_value
38
39
 
39
40
  # instance values that must be serialized as their own elements - e.g. not attributes.
40
- CHILD_ELEMENTS = [:value_objects, :color]
41
+ CHILD_ELEMENTS = [:value_objects, :color].freeze
41
42
 
42
43
  # minLength attribute
43
44
  # The minimum length of the data bar, as a percentage of the cell width.
@@ -71,7 +72,7 @@ module Axlsx
71
72
  # the color object used in the data bar formatting
72
73
  # @return [Color]
73
74
  def color
74
- @color ||= Color.new :rgb => "FF0000FF"
75
+ @color ||= Color.new rgb: "FF0000FF"
75
76
  end
76
77
 
77
78
  # @see minLength
@@ -81,35 +82,34 @@ module Axlsx
81
82
  end
82
83
  alias :minLength= :min_length=
83
84
 
84
- # @see maxLength
85
- def max_length=(v)
86
- Axlsx.validate_unsigned_int(v)
87
- @max_length = v
88
- end
85
+ # @see maxLength
86
+ def max_length=(v)
87
+ Axlsx.validate_unsigned_int(v)
88
+ @max_length = v
89
+ end
89
90
  alias :maxLength= :max_length=
90
91
 
91
- # @see showValue
92
- def show_value=(v)
93
- Axlsx.validate_boolean(v)
94
- @show_value = v
95
- end
92
+ # @see showValue
93
+ def show_value=(v)
94
+ Axlsx.validate_boolean(v)
95
+ @show_value = v
96
+ end
96
97
  alias :showValue= :show_value=
97
98
 
98
- # Sets the color for the data bars.
99
- # @param [Color|String] v The color object, or rgb string value to apply
100
- def color=(v)
101
- @color = v if v.is_a? Color
102
- self.color.rgb = v if v.is_a? String
103
- @color
104
- end
99
+ # Sets the color for the data bars.
100
+ # @param [Color|String] v The color object, or rgb string value to apply
101
+ def color=(v)
102
+ @color = v if v.is_a? Color
103
+ color.rgb = v if v.is_a? String
104
+ end
105
105
 
106
106
  # Serialize this object to an xml string
107
107
  # @param [String] str
108
108
  # @return [String]
109
- def to_xml_string(str="")
109
+ def to_xml_string(str = +'')
110
110
  serialized_tag('dataBar', str) do
111
111
  value_objects.to_xml_string(str)
112
- self.color.to_xml_string(str)
112
+ color.to_xml_string(str)
113
113
  end
114
114
  end
115
115
 
@@ -117,13 +117,12 @@ module Axlsx
117
117
 
118
118
  def initialize_cfvos(cfvos)
119
119
  self.class.default_cfvos.each_with_index.map do |default, index|
120
- if index < cfvos.size
121
- value_objects << Cfvo.new(default.merge(cfvos[index]))
122
- else
123
- value_objects << Cfvo.new(default)
124
- end
120
+ value_objects << if index < cfvos.size
121
+ Cfvo.new(default.merge(cfvos[index]))
122
+ else
123
+ Cfvo.new(default)
124
+ end
125
125
  end
126
126
  end
127
-
128
127
  end
129
128
  end