caxlsx 3.4.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/README.md +9 -11
  4. data/Rakefile +7 -5
  5. data/lib/axlsx/content_type/abstract_content_type.rb +9 -4
  6. data/lib/axlsx/content_type/content_type.rb +7 -5
  7. data/lib/axlsx/content_type/default.rb +4 -2
  8. data/lib/axlsx/content_type/override.rb +4 -2
  9. data/lib/axlsx/doc_props/app.rb +26 -24
  10. data/lib/axlsx/doc_props/core.rb +8 -6
  11. data/lib/axlsx/drawing/area_chart.rb +10 -8
  12. data/lib/axlsx/drawing/area_series.rb +12 -10
  13. data/lib/axlsx/drawing/ax_data_source.rb +2 -0
  14. data/lib/axlsx/drawing/axes.rb +6 -4
  15. data/lib/axlsx/drawing/axis.rb +21 -19
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -12
  17. data/lib/axlsx/drawing/bar_chart.rb +13 -11
  18. data/lib/axlsx/drawing/bar_series.rb +8 -6
  19. data/lib/axlsx/drawing/bubble_chart.rb +6 -4
  20. data/lib/axlsx/drawing/bubble_series.rb +8 -6
  21. data/lib/axlsx/drawing/cat_axis.rb +12 -10
  22. data/lib/axlsx/drawing/chart.rb +20 -18
  23. data/lib/axlsx/drawing/d_lbls.rb +7 -5
  24. data/lib/axlsx/drawing/drawing.rb +58 -56
  25. data/lib/axlsx/drawing/graphic_frame.rb +6 -4
  26. data/lib/axlsx/drawing/hyperlink.rb +10 -8
  27. data/lib/axlsx/drawing/line_3D_chart.rb +7 -5
  28. data/lib/axlsx/drawing/line_chart.rb +10 -8
  29. data/lib/axlsx/drawing/line_series.rb +12 -10
  30. data/lib/axlsx/drawing/marker.rb +9 -7
  31. data/lib/axlsx/drawing/num_data.rb +9 -7
  32. data/lib/axlsx/drawing/num_data_source.rb +9 -7
  33. data/lib/axlsx/drawing/num_val.rb +7 -5
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +7 -5
  35. data/lib/axlsx/drawing/pic.rb +16 -14
  36. data/lib/axlsx/drawing/picture_locking.rb +3 -1
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +5 -3
  38. data/lib/axlsx/drawing/pie_series.rb +8 -6
  39. data/lib/axlsx/drawing/scaling.rb +8 -6
  40. data/lib/axlsx/drawing/scatter_chart.rb +7 -5
  41. data/lib/axlsx/drawing/scatter_series.rb +14 -12
  42. data/lib/axlsx/drawing/ser_axis.rb +7 -5
  43. data/lib/axlsx/drawing/series.rb +6 -4
  44. data/lib/axlsx/drawing/series_title.rb +6 -4
  45. data/lib/axlsx/drawing/str_data.rb +7 -5
  46. data/lib/axlsx/drawing/str_val.rb +6 -4
  47. data/lib/axlsx/drawing/title.rb +13 -14
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +4 -2
  49. data/lib/axlsx/drawing/val_axis.rb +4 -2
  50. data/lib/axlsx/drawing/view_3D.rb +9 -7
  51. data/lib/axlsx/drawing/vml_drawing.rb +18 -16
  52. data/lib/axlsx/drawing/vml_shape.rb +24 -22
  53. data/lib/axlsx/package.rb +69 -66
  54. data/lib/axlsx/rels/relationship.rb +10 -5
  55. data/lib/axlsx/rels/relationships.rb +5 -3
  56. data/lib/axlsx/stylesheet/border.rb +6 -4
  57. data/lib/axlsx/stylesheet/border_pr.rb +5 -3
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +12 -10
  59. data/lib/axlsx/stylesheet/cell_protection.rb +5 -3
  60. data/lib/axlsx/stylesheet/cell_style.rb +10 -8
  61. data/lib/axlsx/stylesheet/color.rb +9 -7
  62. data/lib/axlsx/stylesheet/dxf.rb +5 -3
  63. data/lib/axlsx/stylesheet/fill.rb +3 -1
  64. data/lib/axlsx/stylesheet/font.rb +18 -16
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +6 -4
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +6 -4
  67. data/lib/axlsx/stylesheet/num_fmt.rb +8 -10
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +5 -3
  69. data/lib/axlsx/stylesheet/styles.rb +69 -71
  70. data/lib/axlsx/stylesheet/table_style.rb +7 -5
  71. data/lib/axlsx/stylesheet/table_style_element.rb +6 -4
  72. data/lib/axlsx/stylesheet/table_styles.rb +6 -4
  73. data/lib/axlsx/stylesheet/xf.rb +18 -16
  74. data/lib/axlsx/util/accessors.rb +4 -2
  75. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  76. data/lib/axlsx/util/constants.rb +117 -104
  77. data/lib/axlsx/util/mime_type_utils.rb +3 -5
  78. data/lib/axlsx/util/options_parser.rb +3 -1
  79. data/lib/axlsx/util/serialized_attributes.rb +42 -17
  80. data/lib/axlsx/util/simple_typed_list.rb +47 -47
  81. data/lib/axlsx/util/storage.rb +11 -10
  82. data/lib/axlsx/util/validators.rb +101 -41
  83. data/lib/axlsx/util/zip_command.rb +10 -10
  84. data/lib/axlsx/version.rb +3 -1
  85. data/lib/axlsx/workbook/defined_name.rb +6 -4
  86. data/lib/axlsx/workbook/defined_names.rb +3 -1
  87. data/lib/axlsx/workbook/shared_strings_table.rb +8 -6
  88. data/lib/axlsx/workbook/workbook.rb +78 -76
  89. data/lib/axlsx/workbook/workbook_view.rb +3 -1
  90. data/lib/axlsx/workbook/workbook_views.rb +3 -1
  91. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +65 -8
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +7 -3
  93. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +11 -7
  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 +5 -3
  97. data/lib/axlsx/workbook/worksheet/break.rb +3 -1
  98. data/lib/axlsx/workbook/worksheet/cell.rb +53 -54
  99. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +31 -27
  100. data/lib/axlsx/workbook/worksheet/cfvo.rb +5 -3
  101. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -1
  102. data/lib/axlsx/workbook/worksheet/col.rb +5 -3
  103. data/lib/axlsx/workbook/worksheet/col_breaks.rb +5 -3
  104. data/lib/axlsx/workbook/worksheet/color_scale.rb +12 -10
  105. data/lib/axlsx/workbook/worksheet/cols.rb +3 -1
  106. data/lib/axlsx/workbook/worksheet/comment.rb +8 -6
  107. data/lib/axlsx/workbook/worksheet/comments.rb +6 -4
  108. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +9 -4
  109. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +18 -16
  110. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +3 -1
  111. data/lib/axlsx/workbook/worksheet/data_bar.rb +14 -13
  112. data/lib/axlsx/workbook/worksheet/data_validation.rb +30 -28
  113. data/lib/axlsx/workbook/worksheet/data_validations.rb +3 -1
  114. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +7 -5
  115. data/lib/axlsx/workbook/worksheet/dimension.rb +4 -2
  116. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -2
  117. data/lib/axlsx/workbook/worksheet/icon_set.rb +23 -6
  118. data/lib/axlsx/workbook/worksheet/merged_cells.rb +5 -5
  119. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -2
  120. data/lib/axlsx/workbook/worksheet/page_margins.rb +15 -10
  121. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -2
  122. data/lib/axlsx/workbook/worksheet/page_setup.rb +11 -9
  123. data/lib/axlsx/workbook/worksheet/pane.rb +11 -9
  124. data/lib/axlsx/workbook/worksheet/pivot_table.rb +20 -19
  125. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -6
  126. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +2 -0
  127. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -1
  128. data/lib/axlsx/workbook/worksheet/protected_range.rb +3 -1
  129. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -3
  130. data/lib/axlsx/workbook/worksheet/rich_text.rb +3 -1
  131. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +16 -14
  132. data/lib/axlsx/workbook/worksheet/row.rb +6 -7
  133. data/lib/axlsx/workbook/worksheet/row_breaks.rb +6 -4
  134. data/lib/axlsx/workbook/worksheet/selection.rb +9 -7
  135. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -2
  136. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  137. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +6 -2
  138. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +8 -4
  139. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +10 -8
  140. data/lib/axlsx/workbook/worksheet/sheet_view.rb +15 -13
  141. data/lib/axlsx/workbook/worksheet/table.rb +9 -7
  142. data/lib/axlsx/workbook/worksheet/table_style_info.rb +4 -2
  143. data/lib/axlsx/workbook/worksheet/tables.rb +3 -1
  144. data/lib/axlsx/workbook/worksheet/worksheet.rb +38 -37
  145. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -2
  146. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +8 -2
  147. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +6 -4
  148. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +4 -2
  149. data/lib/axlsx.rb +56 -42
  150. data/lib/caxlsx.rb +3 -1
  151. metadata +49 -43
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A collection of Brake objects.
3
5
  # Please do not use this class directly. Instead use
@@ -14,7 +16,7 @@ module Axlsx
14
16
  # Break will be passed to the created break object.
15
17
  # @see Break
16
18
  def add_break(options)
17
- self << Break.new(options.merge(:max => 1048575, :man => true))
19
+ self << Break.new(options.merge(max: 1048575, man: true))
18
20
  last
19
21
  end
20
22
 
@@ -23,10 +25,10 @@ module Axlsx
23
25
  # <colBreaks count="1" manualBreakCount="1">
24
26
  # <brk id="3" max="1048575" man="1"/>
25
27
  # </colBreaks>
26
- def to_xml_string(str = '')
28
+ def to_xml_string(str = +'')
27
29
  return if empty?
28
30
 
29
- str << ('<colBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">')
31
+ str << '<colBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">'
30
32
  each { |brk| brk.to_xml_string(str) }
31
33
  str << '</colBreaks>'
32
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.
@@ -10,8 +12,8 @@ module Axlsx
10
12
  # These are the default conditional formatting value objects
11
13
  # that define a two tone color gradient.
12
14
  def default_cfvos
13
- [{ :type => :min, :val => 0, :color => 'FFFF7128' },
14
- { :type => :max, :val => 0, :color => 'FFFFEF9C' }]
15
+ [{ type: :min, val: 0, color: 'FFFF7128' },
16
+ { type: :max, val: 0, color: 'FFFFEF9C' }]
15
17
  end
16
18
 
17
19
  # A builder for two tone color gradient
@@ -20,7 +22,7 @@ module Axlsx
20
22
  # color_scale = Axlsx::ColorScale.two_tone
21
23
  # @see examples/example.rb conditional formatting examples.
22
24
  def two_tone
23
- self.new
25
+ new
24
26
  end
25
27
 
26
28
  # A builder for three tone color gradient
@@ -29,9 +31,9 @@ module Axlsx
29
31
  # color_scale = Axlsx::ColorScale.three_tone
30
32
  # @see examples/example.rb conditional formatting examples.
31
33
  def three_tone
32
- self.new({ :type => :min, :val => 0, :color => 'FFF8696B' },
33
- { :type => :percent, :val => '50', :color => 'FFFFEB84' },
34
- { :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' })
35
37
  end
36
38
  end
37
39
  # A simple typed list of cfvos
@@ -66,9 +68,9 @@ module Axlsx
66
68
  # @option [Any] val The value of the cfvo to add
67
69
  # @option [String] The rgb color for the cfvo
68
70
  def add(options = {})
69
- value_objects << Cfvo.new(:type => options[:type] || :min, :val => options[:val] || 0)
70
- colors << Color.new(:rgb => options[:color] || "FF000000")
71
- { :cfvo => value_objects.last, :color => colors.last }
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 }
72
74
  end
73
75
 
74
76
  # removes the cfvo and color pair at the index specified.
@@ -82,7 +84,7 @@ module Axlsx
82
84
  # Serialize this color_scale object data to an xml string
83
85
  # @param [String] str
84
86
  # @return [String]
85
- def to_xml_string(str = '')
87
+ def to_xml_string(str = +'')
86
88
  str << '<colorScale>'
87
89
  value_objects.to_xml_string(str)
88
90
  colors.each { |color| color.to_xml_string(str) }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The cols class manages the col object used to manage column widths.
3
5
  # This is where the magic happens with autowidth
@@ -12,7 +14,7 @@ module Axlsx
12
14
  # Serialize the Cols object
13
15
  # @param [String] str
14
16
  # @return [String]
15
- def to_xml_string(str = '')
17
+ def to_xml_string(str = +'')
16
18
  return if empty?
17
19
 
18
20
  str << '<cols>'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A comment is the text data for a comment
3
5
  class Comment
@@ -59,17 +61,17 @@ module Axlsx
59
61
  # serialize the object
60
62
  # @param [String] str
61
63
  # @return [String]
62
- def to_xml_string(str = "")
64
+ def to_xml_string(str = +'')
63
65
  author = @comments.authors[author_index]
64
- str << ('<comment ref="' << ref << '" authorId="' << author_index.to_s << '">')
66
+ str << '<comment ref="' << ref << '" authorId="' << author_index.to_s << '">'
65
67
  str << '<text>'
66
68
  unless author.to_s == ""
67
69
  str << '<r><rPr><b/><color indexed="81"/></rPr>'
68
- str << ("<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>")
70
+ str << "<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>"
69
71
  end
70
72
  str << '<r>'
71
73
  str << '<rPr><color indexed="81"/></rPr>'
72
- str << ('<t>' << ::CGI.escapeHTML(text) << '</t></r></text>')
74
+ str << '<t>' << ::CGI.escapeHTML(text) << '</t></r></text>'
73
75
  str << '</comment>'
74
76
  end
75
77
 
@@ -78,8 +80,8 @@ module Axlsx
78
80
  # initialize the vml shape based on this comment's ref/position in the worksheet.
79
81
  # by default, all columns are 5 columns wide and 5 rows high
80
82
  def initialize_vml_shape
81
- pos = Axlsx::name_to_indices(ref)
82
- @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|
83
85
  vml.left_column = vml.column
84
86
  vml.right_column = vml.column + 2
85
87
  vml.top_row = vml.row
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Comments is a collection of Comment objects for a worksheet
3
5
  class Comments < SimpleTypedList
@@ -18,7 +20,7 @@ module Axlsx
18
20
  # The part name for this object
19
21
  # @return [String]
20
22
  def pn
21
- "#{COMMENT_PN % (index + 1)}"
23
+ format(COMMENT_PN, index + 1)
22
24
  end
23
25
 
24
26
  # Creates a new Comments object
@@ -62,11 +64,11 @@ module Axlsx
62
64
  # serialize the object
63
65
  # @param [String] str
64
66
  # @return [String]
65
- def to_xml_string(str = "")
67
+ def to_xml_string(str = +'')
66
68
  str << '<?xml version="1.0" encoding="UTF-8"?>'
67
- str << ('<comments xmlns="' << XML_NS << '"><authors>')
69
+ str << '<comments xmlns="' << XML_NS << '"><authors>'
68
70
  authors.each do |author|
69
- str << ('<author>' << author.to_s << '</author>')
71
+ str << '<author>' << author.to_s << '</author>'
70
72
  end
71
73
  str << '</authors><commentList>'
72
74
  each do |comment|
@@ -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
  #
@@ -61,7 +63,7 @@ module Axlsx
61
63
  # @see rules
62
64
  def rules=(v); @rules = v end
63
65
  # @see sqref
64
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
66
+ def sqref=(v); Axlsx.validate_string(v); @sqref = v end
65
67
 
66
68
  # Serializes the conditional formatting element
67
69
  # @example Conditional Formatting XML looks like:
@@ -72,9 +74,12 @@ module Axlsx
72
74
  # </conditionalFormatting>
73
75
  # @param [String] str
74
76
  # @return [String]
75
- def to_xml_string(str = '')
76
- str << ('<conditionalFormatting sqref="' << sqref << '">')
77
- 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
78
83
  str << '</conditionalFormatting>'
79
84
  end
80
85
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Conditional formatting rules specify formulas whose evaluations
3
5
  # format cells
@@ -153,33 +155,33 @@ module Axlsx
153
155
  end
154
156
 
155
157
  # @see type
156
- 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
157
159
  # @see aboveAverage
158
- def aboveAverage=(v); Axlsx::validate_boolean(v); @aboveAverage = v end
160
+ def aboveAverage=(v); Axlsx.validate_boolean(v); @aboveAverage = v end
159
161
  # @see bottom
160
- def bottom=(v); Axlsx::validate_boolean(v); @bottom = v end
162
+ def bottom=(v); Axlsx.validate_boolean(v); @bottom = v end
161
163
  # @see dxfId
162
- def dxfId=(v); Axlsx::validate_unsigned_numeric(v); @dxfId = v end
164
+ def dxfId=(v); Axlsx.validate_unsigned_numeric(v); @dxfId = v end
163
165
  # @see equalAverage
164
- def equalAverage=(v); Axlsx::validate_boolean(v); @equalAverage = v end
166
+ def equalAverage=(v); Axlsx.validate_boolean(v); @equalAverage = v end
165
167
  # @see priority
166
- def priority=(v); Axlsx::validate_unsigned_numeric(v); @priority = v end
168
+ def priority=(v); Axlsx.validate_unsigned_numeric(v); @priority = v end
167
169
  # @see operator
168
- 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
169
171
  # @see text
170
- def text=(v); Axlsx::validate_string(v); @text = v end
172
+ def text=(v); Axlsx.validate_string(v); @text = v end
171
173
  # @see percent
172
- def percent=(v); Axlsx::validate_boolean(v); @percent = v end
174
+ def percent=(v); Axlsx.validate_boolean(v); @percent = v end
173
175
  # @see rank
174
- def rank=(v); Axlsx::validate_unsigned_numeric(v); @rank = v end
176
+ def rank=(v); Axlsx.validate_unsigned_numeric(v); @rank = v end
175
177
  # @see stdDev
176
- def stdDev=(v); Axlsx::validate_unsigned_numeric(v); @stdDev = v end
178
+ def stdDev=(v); Axlsx.validate_unsigned_numeric(v); @stdDev = v end
177
179
  # @see stopIfTrue
178
- def stopIfTrue=(v); Axlsx::validate_boolean(v); @stopIfTrue = v end
180
+ def stopIfTrue=(v); Axlsx.validate_boolean(v); @stopIfTrue = v end
179
181
  # @see timePeriod
180
- 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
181
183
  # @see formula
182
- 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
183
185
 
184
186
  # @see color_scale
185
187
  def color_scale=(v)
@@ -202,11 +204,11 @@ module Axlsx
202
204
  # Serializes the conditional formatting rule
203
205
  # @param [String] str
204
206
  # @return [String]
205
- def to_xml_string(str = '')
207
+ def to_xml_string(str = +'')
206
208
  str << '<cfRule '
207
209
  serialized_attributes str
208
210
  str << '>'
209
- str << ('<formula>' << [*self.formula].join('</formula><formula>') << '</formula>') if @formula
211
+ str << '<formula>' << [*formula].join('</formula><formula>') << '</formula>' if @formula
210
212
  @color_scale.to_xml_string(str) if @color_scale && @type == :colorScale
211
213
  @data_bar.to_xml_string(str) if @data_bar && @type == :dataBar
212
214
  @icon_set.to_xml_string(str) if @icon_set && @type == :iconSet
@@ -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 ConditionalFormattings < SimpleTypedList
@@ -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
  each { |item| item.to_xml_string(str) }
@@ -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,73 @@ 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); Axlsx.validate_string(v); @formula1 = v end
180
182
 
181
183
  # @see formula2
182
- def formula2=(v); Axlsx::validate_string(v); @formula2 = v end
184
+ def formula2=(v); Axlsx.validate_string(v); @formula2 = v end
183
185
 
184
186
  # @see allowBlank
185
- def allowBlank=(v); Axlsx::validate_boolean(v); @allowBlank = v end
187
+ def allowBlank=(v); Axlsx.validate_boolean(v); @allowBlank = v end
186
188
 
187
189
  # @see error
188
- def error=(v); Axlsx::validate_string(v); @error = v end
190
+ def error=(v); Axlsx.validate_string(v); @error = v end
189
191
 
190
192
  # @see errorStyle
191
- def errorStyle=(v); Axlsx::validate_data_validation_error_style(v); @errorStyle = v end
193
+ def errorStyle=(v); Axlsx.validate_data_validation_error_style(v); @errorStyle = v end
192
194
 
193
195
  # @see errorTitle
194
- def errorTitle=(v); Axlsx::validate_string(v); @errorTitle = v end
196
+ def errorTitle=(v); Axlsx.validate_string(v); @errorTitle = v end
195
197
 
196
198
  # @see operator
197
- def operator=(v); Axlsx::validate_data_validation_operator(v); @operator = v end
199
+ def operator=(v); Axlsx.validate_data_validation_operator(v); @operator = v end
198
200
 
199
201
  # @see prompt
200
- def prompt=(v); Axlsx::validate_string(v); @prompt = v end
202
+ def prompt=(v); Axlsx.validate_string(v); @prompt = v end
201
203
 
202
204
  # @see promptTitle
203
- def promptTitle=(v); Axlsx::validate_string(v); @promptTitle = v end
205
+ def promptTitle=(v); Axlsx.validate_string(v); @promptTitle = v end
204
206
 
205
207
  # @see showDropDown
206
208
  def showDropDown=(v)
207
209
  warn 'The `showDropDown` has an inverted logic, false shows the dropdown list! You should use `hideDropDown` instead.'
208
- Axlsx::validate_boolean(v)
210
+ Axlsx.validate_boolean(v)
209
211
  @showDropDown = v
210
212
  end
211
213
 
212
214
  # @see hideDropDown
213
215
  def hideDropDown=(v)
214
- Axlsx::validate_boolean(v)
216
+ Axlsx.validate_boolean(v)
215
217
  # It's just an alias for the showDropDown attribute, hideDropDown should set the value of the original showDropDown.
216
218
  @showDropDown = v
217
219
  end
218
220
 
219
221
  # @see showErrorMessage
220
- def showErrorMessage=(v); Axlsx::validate_boolean(v); @showErrorMessage = v end
222
+ def showErrorMessage=(v); Axlsx.validate_boolean(v); @showErrorMessage = v end
221
223
 
222
224
  # @see showInputMessage
223
- def showInputMessage=(v); Axlsx::validate_boolean(v); @showInputMessage = v end
225
+ def showInputMessage=(v); Axlsx.validate_boolean(v); @showInputMessage = v end
224
226
 
225
227
  # @see sqref
226
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
228
+ def sqref=(v); Axlsx.validate_string(v); @sqref = v end
227
229
 
228
230
  # @see type
229
- def type=(v); Axlsx::validate_data_validation_type(v); @type = v end
231
+ def type=(v); Axlsx.validate_data_validation_type(v); @type = v end
230
232
 
231
233
  # Serializes the data validation
232
234
  # @param [String] str
233
235
  # @return [String]
234
- def to_xml_string(str = '')
236
+ def to_xml_string(str = +'')
235
237
  valid_attributes = get_valid_attributes
238
+ h = Axlsx.instance_values_for(self).select { |key, _| valid_attributes.include?(key.to_sym) && !CHILD_ELEMENTS.include?(key.to_sym) }
236
239
 
237
240
  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(' ')
241
+ h.each_with_index do |key_value, index|
242
+ str << ' ' unless index.zero?
243
+ str << key_value.first << '="' << Axlsx.booleanize(key_value.last).to_s << '"'
244
+ end
241
245
  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)
246
+ str << '<formula1>' << formula1 << '</formula1>' if formula1 && valid_attributes.include?(:formula1)
247
+ str << '<formula2>' << formula2 << '</formula2>' if formula2 && valid_attributes.include?(:formula2)
244
248
  str << '</dataValidation>'
245
249
  end
246
250
 
@@ -250,17 +254,15 @@ module Axlsx
250
254
  attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type]
251
255
 
252
256
  if [:whole, :decimal, :data, :time, :date, :textLength].include?(@type)
253
- attributes << [:operator, :formula1]
254
- attributes << [:formula2] if [:between, :notBetween].include?(@operator)
257
+ attributes << :operator << :formula1
258
+ attributes << :formula2 if [:between, :notBetween].include?(@operator)
255
259
  elsif @type == :list
256
- attributes << [:showDropDown, :formula1]
260
+ attributes << :showDropDown << :formula1
257
261
  elsif @type == :custom
258
- attributes << [:formula1]
259
- else
260
- attributes = []
262
+ attributes << :formula1
261
263
  end
262
264
 
263
- attributes.flatten!
265
+ attributes
264
266
  end
265
267
  end
266
268
  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
@@ -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,8 +50,20 @@ 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); Axlsx.validate_icon_set(v); @iconSet = v end
60
+
61
+ # @see interpolationPoints
62
+ def interpolationPoints=(v)
63
+ v.each { |point| Axlsx.validate_int(point) }
64
+ @value_objects = nil
65
+ @interpolationPoints = v
66
+ end
51
67
 
52
68
  # @see showValue
53
69
  def showValue=(v); Axlsx.validate_boolean(v); @showValue = v end
@@ -61,7 +77,9 @@ module Axlsx
61
77
  # Serialize this object to an xml string
62
78
  # @param [String] str
63
79
  # @return [String]
64
- def to_xml_string(str = "")
80
+ def to_xml_string(str = +'')
81
+ initialize_value_objects if @value_objects.nil?
82
+
65
83
  serialized_tag('iconSet', str) do
66
84
  @value_objects.each { |cfvo| cfvo.to_xml_string(str) }
67
85
  end
@@ -70,10 +88,9 @@ module Axlsx
70
88
  private
71
89
 
72
90
  # 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
91
  def initialize_value_objects
75
92
  @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)]
93
+ @interpolationPoints.each { |point| @value_objects << Cfvo.new(type: :percent, val: point) }
77
94
  @value_objects.lock
78
95
  end
79
96
  end