caxlsx 3.3.0 → 4.5.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 (155) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -11
  3. data/README.md +43 -16
  4. data/Rakefile +5 -11
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +15 -10
  7. data/lib/axlsx/content_type/content_type.rb +8 -10
  8. data/lib/axlsx/content_type/default.rb +7 -6
  9. data/lib/axlsx/content_type/override.rb +6 -5
  10. data/lib/axlsx/doc_props/app.rb +96 -32
  11. data/lib/axlsx/doc_props/core.rb +9 -12
  12. data/lib/axlsx/drawing/area_chart.rb +16 -17
  13. data/lib/axlsx/drawing/area_series.rb +23 -18
  14. data/lib/axlsx/drawing/ax_data_source.rb +4 -7
  15. data/lib/axlsx/drawing/axes.rb +11 -10
  16. data/lib/axlsx/drawing/axis.rb +83 -36
  17. data/lib/axlsx/drawing/bar_3D_chart.rb +30 -21
  18. data/lib/axlsx/drawing/bar_chart.rb +29 -20
  19. data/lib/axlsx/drawing/bar_series.rb +23 -18
  20. data/lib/axlsx/drawing/bubble_chart.rb +9 -10
  21. data/lib/axlsx/drawing/bubble_series.rb +11 -12
  22. data/lib/axlsx/drawing/cat_axis.rb +38 -28
  23. data/lib/axlsx/drawing/chart.rb +52 -30
  24. data/lib/axlsx/drawing/d_lbls.rb +36 -32
  25. data/lib/axlsx/drawing/drawing.rb +61 -62
  26. data/lib/axlsx/drawing/graphic_frame.rb +6 -7
  27. data/lib/axlsx/drawing/hyperlink.rb +22 -14
  28. data/lib/axlsx/drawing/line_3D_chart.rb +15 -17
  29. data/lib/axlsx/drawing/line_chart.rb +16 -17
  30. data/lib/axlsx/drawing/line_series.rb +23 -18
  31. data/lib/axlsx/drawing/marker.rb +29 -16
  32. data/lib/axlsx/drawing/num_data.rb +13 -16
  33. data/lib/axlsx/drawing/num_data_source.rb +11 -13
  34. data/lib/axlsx/drawing/num_val.rb +10 -11
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +16 -10
  36. data/lib/axlsx/drawing/pic.rb +68 -24
  37. data/lib/axlsx/drawing/picture_locking.rb +6 -7
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +9 -12
  39. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  40. data/lib/axlsx/drawing/pie_series.rb +26 -17
  41. data/lib/axlsx/drawing/scaling.rb +26 -13
  42. data/lib/axlsx/drawing/scatter_chart.rb +10 -11
  43. data/lib/axlsx/drawing/scatter_series.rb +17 -18
  44. data/lib/axlsx/drawing/ser_axis.rb +22 -19
  45. data/lib/axlsx/drawing/series.rb +14 -8
  46. data/lib/axlsx/drawing/series_title.rb +6 -6
  47. data/lib/axlsx/drawing/str_data.rb +10 -13
  48. data/lib/axlsx/drawing/str_val.rb +8 -9
  49. data/lib/axlsx/drawing/title.rb +23 -27
  50. data/lib/axlsx/drawing/two_cell_anchor.rb +9 -9
  51. data/lib/axlsx/drawing/val_axis.rb +7 -8
  52. data/lib/axlsx/drawing/view_3D.rb +38 -30
  53. data/lib/axlsx/drawing/vml_drawing.rb +19 -20
  54. data/lib/axlsx/drawing/vml_shape.rb +25 -26
  55. data/lib/axlsx/package.rb +134 -99
  56. data/lib/axlsx/rels/relationship.rb +42 -30
  57. data/lib/axlsx/rels/relationships.rb +9 -10
  58. data/lib/axlsx/stylesheet/border.rb +16 -8
  59. data/lib/axlsx/stylesheet/border_pr.rb +24 -12
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +44 -21
  61. data/lib/axlsx/stylesheet/cell_protection.rb +13 -7
  62. data/lib/axlsx/stylesheet/cell_style.rb +36 -15
  63. data/lib/axlsx/stylesheet/color.rb +23 -14
  64. data/lib/axlsx/stylesheet/dxf.rb +36 -15
  65. data/lib/axlsx/stylesheet/fill.rb +7 -6
  66. data/lib/axlsx/stylesheet/font.rb +71 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +16 -10
  68. data/lib/axlsx/stylesheet/gradient_stop.rb +14 -6
  69. data/lib/axlsx/stylesheet/num_fmt.rb +15 -14
  70. data/lib/axlsx/stylesheet/pattern_fill.rb +20 -8
  71. data/lib/axlsx/stylesheet/styles.rb +167 -118
  72. data/lib/axlsx/stylesheet/table_style.rb +20 -10
  73. data/lib/axlsx/stylesheet/table_style_element.rb +16 -8
  74. data/lib/axlsx/stylesheet/table_styles.rb +16 -11
  75. data/lib/axlsx/stylesheet/theme.rb +163 -0
  76. data/lib/axlsx/stylesheet/xf.rb +78 -25
  77. data/lib/axlsx/util/accessors.rb +13 -11
  78. data/lib/axlsx/util/buffered_zip_output_stream.rb +64 -0
  79. data/lib/axlsx/util/constants.rb +133 -110
  80. data/lib/axlsx/util/mime_type_utils.rb +75 -5
  81. data/lib/axlsx/util/options_parser.rb +4 -3
  82. data/lib/axlsx/util/serialized_attributes.rb +47 -23
  83. data/lib/axlsx/util/simple_typed_list.rb +77 -64
  84. data/lib/axlsx/util/storage.rb +38 -41
  85. data/lib/axlsx/util/uri_utils.rb +70 -0
  86. data/lib/axlsx/util/validators.rb +111 -48
  87. data/lib/axlsx/util/zip_command.rb +10 -12
  88. data/lib/axlsx/version.rb +3 -2
  89. data/lib/axlsx/workbook/defined_name.rb +13 -9
  90. data/lib/axlsx/workbook/defined_names.rb +5 -4
  91. data/lib/axlsx/workbook/shared_strings_table.rb +13 -14
  92. data/lib/axlsx/workbook/workbook.rb +152 -120
  93. data/lib/axlsx/workbook/workbook_view.rb +9 -12
  94. data/lib/axlsx/workbook/workbook_views.rb +5 -5
  95. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +87 -15
  96. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +16 -10
  97. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +28 -25
  98. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  99. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +54 -0
  100. data/lib/axlsx/workbook/worksheet/border_creator.rb +34 -29
  101. data/lib/axlsx/workbook/worksheet/break.rb +4 -5
  102. data/lib/axlsx/workbook/worksheet/cell.rb +125 -78
  103. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +33 -29
  104. data/lib/axlsx/workbook/worksheet/cfvo.rb +13 -5
  105. data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
  106. data/lib/axlsx/workbook/worksheet/col.rb +32 -19
  107. data/lib/axlsx/workbook/worksheet/col_breaks.rb +9 -8
  108. data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
  109. data/lib/axlsx/workbook/worksheet/cols.rb +10 -8
  110. data/lib/axlsx/workbook/worksheet/comment.rb +14 -13
  111. data/lib/axlsx/workbook/worksheet/comments.rb +11 -13
  112. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +19 -9
  113. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +75 -22
  114. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +8 -8
  115. data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
  116. data/lib/axlsx/workbook/worksheet/data_validation.rb +73 -33
  117. data/lib/axlsx/workbook/worksheet/data_validations.rb +8 -9
  118. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
  119. data/lib/axlsx/workbook/worksheet/dimension.rb +10 -7
  120. data/lib/axlsx/workbook/worksheet/header_footer.rb +5 -4
  121. data/lib/axlsx/workbook/worksheet/icon_set.rb +40 -12
  122. data/lib/axlsx/workbook/worksheet/merged_cells.rb +11 -11
  123. data/lib/axlsx/workbook/worksheet/outline_pr.rb +7 -4
  124. data/lib/axlsx/workbook/worksheet/page_margins.rb +41 -13
  125. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -6
  126. data/lib/axlsx/workbook/worksheet/page_setup.rb +153 -131
  127. data/lib/axlsx/workbook/worksheet/pane.rb +34 -26
  128. data/lib/axlsx/workbook/worksheet/pivot_table.rb +78 -29
  129. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
  130. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +6 -5
  131. data/lib/axlsx/workbook/worksheet/print_options.rb +4 -2
  132. data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
  133. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +13 -11
  134. data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
  135. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +66 -28
  136. data/lib/axlsx/workbook/worksheet/row.rb +34 -23
  137. data/lib/axlsx/workbook/worksheet/row_breaks.rb +9 -8
  138. data/lib/axlsx/workbook/worksheet/selection.rb +22 -16
  139. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +11 -7
  140. data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
  141. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
  142. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +12 -8
  143. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +22 -21
  144. data/lib/axlsx/workbook/worksheet/sheet_view.rb +71 -55
  145. data/lib/axlsx/workbook/worksheet/table.rb +13 -13
  146. data/lib/axlsx/workbook/worksheet/table_style_info.rb +8 -6
  147. data/lib/axlsx/workbook/worksheet/tables.rb +8 -6
  148. data/lib/axlsx/workbook/worksheet/worksheet.rb +120 -79
  149. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +13 -11
  150. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
  151. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +12 -10
  152. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +9 -7
  153. data/lib/axlsx.rb +120 -60
  154. data/lib/caxlsx.rb +3 -2
  155. metadata +42 -75
@@ -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
 
@@ -24,9 +24,9 @@ module Axlsx
24
24
  # @option options [Integer] rank If a top/bottom N rule, the value of N
25
25
  # @option options [Integer] stdDev The number of standard deviations above or below the average to match
26
26
  # @option options [Boolean] stopIfTrue Stop evaluating rules after this rule matches
27
- # @option options [Symbol] timePeriod The time period in a date occuring... rule
27
+ # @option options [Symbol] timePeriod The time period in a date occurring... 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,88 @@ 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)
159
+ Axlsx.validate_conditional_formatting_type(v)
160
+ @type = v
161
+ end
162
+
160
163
  # @see aboveAverage
161
- def aboveAverage=(v); Axlsx::validate_boolean(v); @aboveAverage = v end
164
+ def aboveAverage=(v)
165
+ Axlsx.validate_boolean(v)
166
+ @aboveAverage = v
167
+ end
168
+
162
169
  # @see bottom
163
- def bottom=(v); Axlsx::validate_boolean(v); @bottom = v end
170
+ def bottom=(v)
171
+ Axlsx.validate_boolean(v)
172
+ @bottom = v
173
+ end
174
+
164
175
  # @see dxfId
165
- def dxfId=(v); Axlsx::validate_unsigned_numeric(v); @dxfId = v end
176
+ def dxfId=(v)
177
+ Axlsx.validate_unsigned_numeric(v)
178
+ @dxfId = v
179
+ end
180
+
166
181
  # @see equalAverage
167
- def equalAverage=(v); Axlsx::validate_boolean(v); @equalAverage = v end
182
+ def equalAverage=(v)
183
+ Axlsx.validate_boolean(v)
184
+ @equalAverage = v
185
+ end
186
+
168
187
  # @see priority
169
- def priority=(v); Axlsx::validate_unsigned_numeric(v); @priority = v end
188
+ def priority=(v)
189
+ Axlsx.validate_unsigned_numeric(v)
190
+ @priority = v
191
+ end
192
+
170
193
  # @see operator
171
- def operator=(v); Axlsx::validate_conditional_formatting_operator(v); @operator = v end
194
+ def operator=(v)
195
+ Axlsx.validate_conditional_formatting_operator(v)
196
+ @operator = v
197
+ end
198
+
172
199
  # @see text
173
- def text=(v); Axlsx::validate_string(v); @text = v end
200
+ def text=(v)
201
+ Axlsx.validate_string(v)
202
+ @text = v
203
+ end
204
+
174
205
  # @see percent
175
- def percent=(v); Axlsx::validate_boolean(v); @percent = v end
206
+ def percent=(v)
207
+ Axlsx.validate_boolean(v)
208
+ @percent = v
209
+ end
210
+
176
211
  # @see rank
177
- def rank=(v); Axlsx::validate_unsigned_numeric(v); @rank = v end
212
+ def rank=(v)
213
+ Axlsx.validate_unsigned_numeric(v)
214
+ @rank = v
215
+ end
216
+
178
217
  # @see stdDev
179
- def stdDev=(v); Axlsx::validate_unsigned_numeric(v); @stdDev = v end
218
+ def stdDev=(v)
219
+ Axlsx.validate_unsigned_numeric(v)
220
+ @stdDev = v
221
+ end
222
+
180
223
  # @see stopIfTrue
181
- def stopIfTrue=(v); Axlsx::validate_boolean(v); @stopIfTrue = v end
224
+ def stopIfTrue=(v)
225
+ Axlsx.validate_boolean(v)
226
+ @stopIfTrue = v
227
+ end
228
+
182
229
  # @see timePeriod
183
- def timePeriod=(v); Axlsx::validate_time_period_type(v); @timePeriod = v end
230
+ def timePeriod=(v)
231
+ Axlsx.validate_time_period_type(v)
232
+ @timePeriod = v
233
+ end
234
+
184
235
  # @see formula
185
- def formula=(v); [*v].each {|x| Axlsx::validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
236
+ def formula=(v)
237
+ [*v].each { |x| Axlsx.validate_string(x) }
238
+ @formula = [*v].map { |form| ::CGI.escapeHTML(form) }
239
+ end
186
240
 
187
241
  # @see color_scale
188
242
  def color_scale=(v)
@@ -202,15 +256,14 @@ module Axlsx
202
256
  @icon_set = v
203
257
  end
204
258
 
205
-
206
259
  # Serializes the conditional formatting rule
207
260
  # @param [String] str
208
261
  # @return [String]
209
- def to_xml_string(str = '')
262
+ def to_xml_string(str = +'')
210
263
  str << '<cfRule '
211
264
  serialized_attributes str
212
265
  str << '>'
213
- str << ('<formula>' << [*self.formula].join('</formula><formula>') << '</formula>') if @formula
266
+ str << '<formula>' << [*formula].join('</formula><formula>') << '</formula>' if @formula
214
267
  @color_scale.to_xml_string(str) if @color_scale && @type == :colorScale
215
268
  @data_bar.to_xml_string(str) if @data_bar && @type == :dataBar
216
269
  @icon_set.to_xml_string(str) if @icon_set && @type == :iconSet
@@ -1,12 +1,13 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
- # A simple, self serializing class for storing conditional formattings
3
+ module Axlsx
4
+ # A simple, self serializing class for storing conditional formatting
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
- super ConditionalFormatting
9
+
10
+ super(ConditionalFormatting)
10
11
  @worksheet = worksheet
11
12
  end
12
13
 
@@ -14,12 +15,11 @@ module Axlsx
14
15
  # @return [Worksheet]
15
16
  attr_reader :worksheet
16
17
 
17
- # serialize the conditional formattings
18
- def to_xml_string(str = "")
18
+ # serialize the conditional formatting
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
@@ -1,4 +1,5 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # Data validation allows the validation of cell data
4
5
  #
@@ -23,7 +24,7 @@ module Axlsx
23
24
  # @option options [Boolean] showInputMessage - A boolean value indicating whether to display the input prompt message.
24
25
  # @option options [String] sqref - Range over which data validation is applied, in "A1:B2" format.
25
26
  # @option options [Symbol] type - The type of data validation.
26
- def initialize(options={})
27
+ def initialize(options = {})
27
28
  # defaults
28
29
  @formula1 = @formula2 = @error = @errorTitle = @operator = @prompt = @promptTitle = @sqref = nil
29
30
  @allowBlank = @showErrorMessage = true
@@ -176,92 +177,131 @@ module Axlsx
176
177
  # default none
177
178
  attr_reader :type
178
179
 
179
-
180
180
  # @see formula1
181
- def formula1=(v); Axlsx::validate_string(v); @formula1 = v end
181
+ def formula1=(v)
182
+ Axlsx.validate_string(v)
183
+ @formula1 = v
184
+ end
182
185
 
183
186
  # @see formula2
184
- def formula2=(v); Axlsx::validate_string(v); @formula2 = v end
187
+ def formula2=(v)
188
+ Axlsx.validate_string(v)
189
+ @formula2 = v
190
+ end
185
191
 
186
192
  # @see allowBlank
187
- def allowBlank=(v); Axlsx::validate_boolean(v); @allowBlank = v end
193
+ def allowBlank=(v)
194
+ Axlsx.validate_boolean(v)
195
+ @allowBlank = v
196
+ end
188
197
 
189
198
  # @see error
190
- def error=(v); Axlsx::validate_string(v); @error = v end
199
+ def error=(v)
200
+ Axlsx.validate_string(v)
201
+ @error = v
202
+ end
191
203
 
192
204
  # @see errorStyle
193
- def errorStyle=(v); Axlsx::validate_data_validation_error_style(v); @errorStyle = v end
205
+ def errorStyle=(v)
206
+ Axlsx.validate_data_validation_error_style(v)
207
+ @errorStyle = v
208
+ end
194
209
 
195
210
  # @see errorTitle
196
- def errorTitle=(v); Axlsx::validate_string(v); @errorTitle = v end
211
+ def errorTitle=(v)
212
+ Axlsx.validate_string(v)
213
+ @errorTitle = v
214
+ end
197
215
 
198
216
  # @see operator
199
- def operator=(v); Axlsx::validate_data_validation_operator(v); @operator = v end
217
+ def operator=(v)
218
+ Axlsx.validate_data_validation_operator(v)
219
+ @operator = v
220
+ end
200
221
 
201
222
  # @see prompt
202
- def prompt=(v); Axlsx::validate_string(v); @prompt = v end
223
+ def prompt=(v)
224
+ Axlsx.validate_string(v)
225
+ @prompt = v
226
+ end
203
227
 
204
228
  # @see promptTitle
205
- def promptTitle=(v); Axlsx::validate_string(v); @promptTitle = v end
229
+ def promptTitle=(v)
230
+ Axlsx.validate_string(v)
231
+ @promptTitle = v
232
+ end
206
233
 
207
234
  # @see showDropDown
208
235
  def showDropDown=(v)
209
236
  warn 'The `showDropDown` has an inverted logic, false shows the dropdown list! You should use `hideDropDown` instead.'
210
- Axlsx::validate_boolean(v)
237
+ Axlsx.validate_boolean(v)
211
238
  @showDropDown = v
212
239
  end
213
240
 
214
241
  # @see hideDropDown
215
242
  def hideDropDown=(v)
216
- Axlsx::validate_boolean(v)
243
+ Axlsx.validate_boolean(v)
217
244
  # It's just an alias for the showDropDown attribute, hideDropDown should set the value of the original showDropDown.
218
245
  @showDropDown = v
219
246
  end
220
247
 
221
248
  # @see showErrorMessage
222
- def showErrorMessage=(v); Axlsx::validate_boolean(v); @showErrorMessage = v end
249
+ def showErrorMessage=(v)
250
+ Axlsx.validate_boolean(v)
251
+ @showErrorMessage = v
252
+ end
223
253
 
224
254
  # @see showInputMessage
225
- def showInputMessage=(v); Axlsx::validate_boolean(v); @showInputMessage = v end
255
+ def showInputMessage=(v)
256
+ Axlsx.validate_boolean(v)
257
+ @showInputMessage = v
258
+ end
226
259
 
227
260
  # @see sqref
228
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
261
+ def sqref=(v)
262
+ Axlsx.validate_string(v)
263
+ @sqref = v
264
+ end
229
265
 
230
266
  # @see type
231
- def type=(v); Axlsx::validate_data_validation_type(v); @type = v end
267
+ def type=(v)
268
+ Axlsx.validate_data_validation_type(v)
269
+ @type = v
270
+ end
232
271
 
233
272
  # Serializes the data validation
234
273
  # @param [String] str
235
274
  # @return [String]
236
- def to_xml_string(str = '')
275
+ def to_xml_string(str = +'')
237
276
  valid_attributes = get_valid_attributes
277
+ h = Axlsx.instance_values_for(self).select { |key, _| valid_attributes.include?(key.to_sym) && !CHILD_ELEMENTS.include?(key.to_sym) }
238
278
 
239
279
  str << '<dataValidation '
240
- str << Axlsx.instance_values_for(self).map do |key, value|
241
- '' << key << '="' << Axlsx.booleanize(value).to_s << '"' if (valid_attributes.include?(key.to_sym) && !CHILD_ELEMENTS.include?(key.to_sym))
242
- end.join(' ')
280
+ h.each_with_index do |key_value, index|
281
+ str << ' ' unless index == 0
282
+ str << key_value.first << '="' << Axlsx.booleanize(key_value.last).to_s << '"'
283
+ end
243
284
  str << '>'
244
- str << ('<formula1>' << self.formula1 << '</formula1>') if @formula1 and valid_attributes.include?(:formula1)
245
- str << ('<formula2>' << self.formula2 << '</formula2>') if @formula2 and valid_attributes.include?(:formula2)
285
+ str << '<formula1>' << formula1 << '</formula1>' if formula1 && valid_attributes.include?(:formula1)
286
+ str << '<formula2>' << formula2 << '</formula2>' if formula2 && valid_attributes.include?(:formula2)
246
287
  str << '</dataValidation>'
247
288
  end
248
289
 
249
- private
290
+ private
291
+
250
292
  def get_valid_attributes
251
- attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type ]
293
+ attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type]
252
294
 
253
295
  if [:whole, :decimal, :data, :time, :date, :textLength].include?(@type)
254
- attributes << [:operator, :formula1]
255
- attributes << [:formula2] if [:between, :notBetween].include?(@operator)
296
+ attributes << :operator << :formula1
297
+ attributes << :formula2 if [:between, :notBetween].include?(@operator)
256
298
  elsif @type == :list
257
- attributes << [:showDropDown, :formula1]
299
+ attributes << :showDropDown << :formula1
258
300
  elsif @type == :custom
259
- attributes << [:formula1]
260
- else
261
- attributes = []
301
+ attributes << :formula1
262
302
  end
263
303
 
264
- attributes.flatten!
304
+ attributes
265
305
  end
266
306
  end
267
307
  end
@@ -1,12 +1,13 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
- # A simple, self serializing class for storing conditional formattings
3
+ module Axlsx
4
+ # A simple, self serializing class for storing conditional formatting
4
5
  class DataValidations < SimpleTypedList
5
-
6
6
  # creates a new Tables object
7
7
  def initialize(worksheet)
8
8
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
9
- super DataValidation
9
+
10
+ super(DataValidation)
10
11
  @worksheet = worksheet
11
12
  end
12
13
 
@@ -14,15 +15,13 @@ module Axlsx
14
15
  # @return [Worksheet]
15
16
  attr_reader :worksheet
16
17
 
17
- # serialize the conditional formattings
18
- def to_xml_string(str = "")
18
+ # serialize the conditional formatting
19
+ def to_xml_string(str = +'')
19
20
  return if empty?
21
+
20
22
  str << "<dataValidations count='#{size}'>"
21
23
  each { |item| item.to_xml_string(str) }
22
24
  str << '</dataValidations>'
23
25
  end
24
26
  end
25
-
26
27
  end
27
-
28
-
@@ -1,20 +1,20 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  require "date"
3
4
 
4
5
  module Axlsx
5
- # The DateTimeConverter class converts both data and time types to their apprpriate excel serializations
6
+ # The DateTimeConverter class converts both data and time types to their appropriate Excel serializations
6
7
  class DateTimeConverter
7
-
8
- # The date_to_serial method converts Date objects to the equivelant excel serialized forms
8
+ # The date_to_serial method converts Date objects to the equivalent Excel serialized forms
9
9
  # @param [Date] date the date to be serialized
10
10
  # @return [Numeric]
11
11
  def self.date_to_serial(date)
12
- epoch = Axlsx::Workbook::date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
12
+ epoch = Axlsx::Workbook.date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
13
13
  offset_date = date.respond_to?(:utc_offset) ? date + date.utc_offset.seconds : date
14
14
  (offset_date - epoch).to_f
15
15
  end
16
16
 
17
- # The time_to_serial methond converts a Time object its excel serialized form.
17
+ # The time_to_serial methond converts a Time object its Excel serialized form.
18
18
  # @param [Time] time the time to be serialized
19
19
  # @return [Numeric]
20
20
  def self.time_to_serial(time)
@@ -23,8 +23,8 @@ module Axlsx
23
23
  epoch1900 = -2209161600.0 # Time.utc(1899, 12, 30).to_i
24
24
  epoch1904 = -2082844800.0 # Time.utc(1904, 1, 1).to_i
25
25
  seconds_per_day = 86400.0 # 60*60*24
26
- epoch = Axlsx::Workbook::date1904 ? epoch1904 : epoch1900
27
- (time.utc_offset + time.to_f - epoch)/seconds_per_day
26
+ epoch = Axlsx::Workbook.date1904 ? epoch1904 : epoch1900
27
+ (time.utc_offset + time.to_f - epoch) / seconds_per_day
28
28
  end
29
29
  end
30
30
  end
@@ -1,10 +1,10 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # This class manages the dimensions for a worksheet.
4
- # While this node is optional in the specification some readers like
5
+ # While this node is optional in the specification some readers like
5
6
  # LibraOffice require this node to render the sheet
6
7
  class Dimension
7
-
8
8
  # the default value for the first cell in the dimension
9
9
  # @return [String]
10
10
  def self.default_first
@@ -22,22 +22,24 @@ module Axlsx
22
22
  # to.
23
23
  def initialize(worksheet)
24
24
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
25
+
25
26
  @worksheet = worksheet
26
27
  end
27
28
 
28
29
  attr_reader :worksheet
29
30
 
30
- # the full refernece for this dimension
31
+ # the full reference for this dimension
31
32
  # @return [String]
32
33
  def sqref
33
34
  "#{first_cell_reference}:#{last_cell_reference}"
34
- end
35
+ end
35
36
 
36
37
  # serialize the object
37
38
  # @return [String]
38
- def to_xml_string(str = '')
39
+ def to_xml_string(str = +'')
39
40
  return if worksheet.rows.empty?
40
- str << "<dimension ref=\"%s\"></dimension>" % sqref
41
+
42
+ str << '<dimension ref="' << sqref << '"></dimension>'
41
43
  end
42
44
 
43
45
  # The first cell in the dimension
@@ -58,6 +60,7 @@ module Axlsx
58
60
  # @return [String]
59
61
  def dimension_reference(cell, default)
60
62
  return default unless cell.respond_to?(:r)
63
+
61
64
  cell.r
62
65
  end
63
66
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Header/Footer options for printing a worksheet. All settings are optional.
3
5
  #
@@ -5,11 +7,10 @@ module Axlsx
5
7
  # of plain text and control characters. A fairly comprehensive list of control
6
8
  # characters can be found here:
7
9
  # https://github.com/randym/axlsx/blob/master/notes_on_header_footer.md
8
- #     
10
+ #
9
11
  # @note The recommended way of managing header/footers is via Worksheet#header_footer
10
12
  # @see Worksheet#initialize
11
13
  class HeaderFooter
12
-
13
14
  include Axlsx::OptionsParser
14
15
  include Axlsx::SerializedAttributes
15
16
  include Axlsx::Accessors
@@ -41,10 +42,10 @@ module Axlsx
41
42
  # Serializes the header/footer object.
42
43
  # @param [String] str
43
44
  # @return [String]
44
- def to_xml_string(str = '')
45
+ def to_xml_string(str = +'')
45
46
  serialized_tag('headerFooter', str) do
46
47
  serialized_element_attributes(str) do |value|
47
- value = ::CGI.escapeHTML(value)
48
+ ::CGI.escapeHTML(value)
48
49
  end
49
50
  end
50
51
  end