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,8 +1,8 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # The RichTextRun class creates and self serializing text run.
4
5
  class RichTextRun
5
-
6
6
  include Axlsx::OptionsParser
7
7
 
8
8
  attr_reader :value
@@ -13,7 +13,7 @@ module Axlsx
13
13
  :shadow, :condense, :extend, :u,
14
14
  :vertAlign, :sz, :color, :scheme].freeze
15
15
 
16
- def initialize(value, options={})
16
+ def initialize(value, options = {})
17
17
  self.value = value
18
18
  parse_options(options)
19
19
  end
@@ -27,8 +27,11 @@ module Axlsx
27
27
  # The inline font_name property for the cell
28
28
  # @return [String]
29
29
  attr_reader :font_name
30
+
30
31
  # @see font_name
31
- def font_name=(v) set_run_style :validate_string, :font_name, v; end
32
+ def font_name=(v)
33
+ set_run_style :validate_string, :font_name, v
34
+ end
32
35
 
33
36
  # The inline charset property for the cell
34
37
  # As far as I can tell, this is pretty much ignored. However, based on the spec it should be one of the following:
@@ -53,8 +56,11 @@ module Axlsx
53
56
  # 255  OEM_CHARSET
54
57
  # @return [String]
55
58
  attr_reader :charset
59
+
56
60
  # @see charset
57
- def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end
61
+ def charset=(v)
62
+ set_run_style :validate_unsigned_int, :charset, v
63
+ end
58
64
 
59
65
  # The inline family property for the cell
60
66
  # @return [Integer]
@@ -64,6 +70,7 @@ module Axlsx
64
70
  # 4 Script
65
71
  # 5 Decorative
66
72
  attr_reader :family
73
+
67
74
  # @see family
68
75
  def family=(v)
69
76
  set_run_style :validate_family, :family, v.to_i
@@ -72,75 +79,102 @@ module Axlsx
72
79
  # The inline bold property for the cell
73
80
  # @return [Boolean]
74
81
  attr_reader :b
82
+
75
83
  # @see b
76
- def b=(v) set_run_style :validate_boolean, :b, v; end
84
+ def b=(v)
85
+ set_run_style :validate_boolean, :b, v
86
+ end
77
87
 
78
88
  # The inline italic property for the cell
79
89
  # @return [Boolean]
80
90
  attr_reader :i
91
+
81
92
  # @see i
82
- def i=(v) set_run_style :validate_boolean, :i, v; end
93
+ def i=(v)
94
+ set_run_style :validate_boolean, :i, v
95
+ end
83
96
 
84
97
  # The inline strike property for the cell
85
98
  # @return [Boolean]
86
99
  attr_reader :strike
100
+
87
101
  # @see strike
88
- def strike=(v) set_run_style :validate_boolean, :strike, v; end
102
+ def strike=(v)
103
+ set_run_style :validate_boolean, :strike, v
104
+ end
89
105
 
90
106
  # The inline outline property for the cell
91
107
  # @return [Boolean]
92
108
  attr_reader :outline
109
+
93
110
  # @see outline
94
- def outline=(v) set_run_style :validate_boolean, :outline, v; end
111
+ def outline=(v)
112
+ set_run_style :validate_boolean, :outline, v
113
+ end
95
114
 
96
115
  # The inline shadow property for the cell
97
116
  # @return [Boolean]
98
117
  attr_reader :shadow
118
+
99
119
  # @see shadow
100
- def shadow=(v) set_run_style :validate_boolean, :shadow, v; end
120
+ def shadow=(v)
121
+ set_run_style :validate_boolean, :shadow, v
122
+ end
101
123
 
102
124
  # The inline condense property for the cell
103
125
  # @return [Boolean]
104
126
  attr_reader :condense
127
+
105
128
  # @see condense
106
- def condense=(v) set_run_style :validate_boolean, :condense, v; end
129
+ def condense=(v)
130
+ set_run_style :validate_boolean, :condense, v
131
+ end
107
132
 
108
133
  # The inline extend property for the cell
109
134
  # @return [Boolean]
110
135
  attr_reader :extend
136
+
111
137
  # @see extend
112
- def extend=(v) set_run_style :validate_boolean, :extend, v; end
138
+ def extend=(v)
139
+ set_run_style :validate_boolean, :extend, v
140
+ end
113
141
 
114
142
  # The inline underline property for the cell.
115
143
  # It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true
116
144
  # @return [Boolean]
117
145
  # @return [String]
118
- # @note true is for backwards compatability and is reassigned to :single
146
+ # @note true is for backwards compatibility and is reassigned to :single
119
147
  attr_reader :u
148
+
120
149
  # @see u
121
150
  def u=(v)
122
- v = :single if (v == true || v == 1 || v == :true || v == 'true')
151
+ v = :single if v == true || v == 1 || v == :true || v == 'true'
123
152
  set_run_style :validate_cell_u, :u, v
124
153
  end
125
154
 
126
155
  # The inline color property for the cell
127
156
  # @return [Color]
128
157
  attr_reader :color
158
+
129
159
  # @param [String] v The 8 character representation for an rgb color #FFFFFFFF"
130
160
  def color=(v)
131
- @color = v.is_a?(Color) ? v : Color.new(:rgb=>v)
161
+ @color = v.is_a?(Color) ? v : Color.new(rgb: v)
132
162
  end
133
163
 
134
164
  # The inline sz property for the cell
135
165
  # @return [Inteter]
136
166
  attr_reader :sz
167
+
137
168
  # @see sz
138
- def sz=(v) set_run_style :validate_unsigned_int, :sz, v; end
169
+ def sz=(v)
170
+ set_run_style :validate_unsigned_int, :sz, v
171
+ end
139
172
 
140
173
  # The inline vertical alignment property for the cell
141
174
  # this must be one of [:baseline, :subscript, :superscript]
142
175
  # @return [Symbol]
143
176
  attr_reader :vertAlign
177
+
144
178
  # @see vertAlign
145
179
  def vertAlign=(v)
146
180
  RestrictionValidator.validate :cell_vertAlign, [:baseline, :subscript, :superscript], v
@@ -151,6 +185,7 @@ module Axlsx
151
185
  # this must be one of [:none, major, minor]
152
186
  # @return [Symbol]
153
187
  attr_reader :scheme
188
+
154
189
  # @see scheme
155
190
  def scheme=(v)
156
191
  RestrictionValidator.validate :cell_scheme, [:none, :major, :minor], v
@@ -162,6 +197,7 @@ module Axlsx
162
197
  # @return [Array]
163
198
  def autowidth(widtharray)
164
199
  return if value.nil?
200
+
165
201
  if styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text
166
202
  first = true
167
203
  value.to_s.split(/\r?\n/, -1).each do |line|
@@ -181,31 +217,32 @@ module Axlsx
181
217
  # Utility method for setting inline style attributes
182
218
  def set_run_style(validator, attr, value)
183
219
  return unless INLINE_STYLES.include?(attr.to_sym)
220
+
184
221
  Axlsx.send(validator, value) unless validator.nil?
185
- self.instance_variable_set :"@#{attr.to_s}", value
222
+ instance_variable_set :"@#{attr}", value
186
223
  end
187
224
 
188
225
  # Serializes the RichTextRun
189
226
  # @param [String] str
190
227
  # @return [String]
191
- def to_xml_string(str = '')
228
+ def to_xml_string(str = +'')
192
229
  valid = RichTextRun::INLINE_STYLES
193
- data = Hash[Axlsx.instance_values_for(self).map{ |k, v| [k.to_sym, v] }]
194
- data = data.select { |key, value| valid.include?(key) && !value.nil? }
230
+ data = Axlsx.instance_values_for(self).transform_keys(&:to_sym)
231
+ data = data.select { |key, value| !value.nil? && valid.include?(key) }
195
232
 
196
233
  str << '<r><rPr>'
197
- data.keys.each do |key|
234
+ data.each do |key, val|
198
235
  case key
199
236
  when :font_name
200
- str << ('<rFont val="' << font_name << '"/>')
237
+ str << '<rFont val="' << font_name << '"/>'
201
238
  when :color
202
- str << data[key].to_xml_string
239
+ str << val.to_xml_string
203
240
  else
204
- str << ('<' << key.to_s << ' val="' << xml_value(data[key]) << '"/>')
241
+ str << '<' << key.to_s << ' val="' << xml_value(val) << '"/>'
205
242
  end
206
243
  end
207
- clean_value = Axlsx::trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@value.to_s))
208
- str << ('</rPr><t>' << clean_value << '</t></r>')
244
+ clean_value = Axlsx.trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx.sanitize(@value.to_s))
245
+ str << '</rPr><t>' << clean_value << '</t></r>'
209
246
  end
210
247
 
211
248
  private
@@ -223,8 +260,9 @@ module Axlsx
223
260
  # imagemagick and loading metrics for every character.
224
261
  def font_size
225
262
  return sz if sz
263
+
226
264
  font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0]
227
- (font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz
265
+ font.b || (defined?(@b) && @b) ? (font.sz * 1.5) : font.sz
228
266
  end
229
267
 
230
268
  def style
@@ -237,7 +275,7 @@ module Axlsx
237
275
 
238
276
  # Converts the value to the correct XML representation (fixes issues with
239
277
  # Numbers)
240
- def xml_value value
278
+ def xml_value(value)
241
279
  if value == true
242
280
  1
243
281
  elsif value == false
@@ -1,4 +1,5 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # A Row is a single row in a worksheet.
4
5
  # @note The recommended way to manage rows and cells is to use Worksheet#add_row
@@ -6,13 +7,13 @@ module Axlsx
6
7
  class Row < SimpleTypedList
7
8
  include SerializedAttributes
8
9
  include Accessors
9
-
10
+
10
11
  # No support is provided for the following attributes
11
12
  # spans
12
13
  # thickTop
13
14
  # thickBottom
14
15
 
15
- # Creates a new row. New Cell objects are created based on the values, types and style options.
16
+ # Creates a new row. New Cell objects are created based on the values, types and style options.
16
17
  # A new cell is created for each item in the values array. style and types options are applied as follows:
17
18
  # If the types option is defined and is a symbol it is applied to all the cells created.
18
19
  # If the types option is an array, cell types are applied by index for each cell
@@ -24,11 +25,12 @@ module Axlsx
24
25
  # @option options [Array] values
25
26
  # @option options [Array, Symbol] types
26
27
  # @option options [Array, Integer] style
28
+ # @option options [Array, Boolean] escape_formulas
27
29
  # @option options [Float] height the row's height (in points)
28
30
  # @option options [Integer] offset - add empty columns before values
29
31
  # @see Row#array_to_cells
30
32
  # @see Cell
31
- def initialize(worksheet, values=[], options={})
33
+ def initialize(worksheet, values = [], options = {})
32
34
  self.worksheet = worksheet
33
35
  super(Cell, nil, values.size + options[:offset].to_i)
34
36
  self.height = options.delete(:height)
@@ -64,7 +66,7 @@ module Axlsx
64
66
  # @see Row#s
65
67
  def s=(v)
66
68
  Axlsx.validate_unsigned_numeric(v)
67
- @custom_format = true
69
+ @custom_format = true
68
70
  @s = v
69
71
  end
70
72
 
@@ -73,7 +75,7 @@ module Axlsx
73
75
  Axlsx.validate_unsigned_numeric(v)
74
76
  @outline_level = v
75
77
  end
76
-
78
+
77
79
  alias :outlineLevel= :outline_level=
78
80
 
79
81
  # The index of this row in the worksheet
@@ -86,12 +88,9 @@ module Axlsx
86
88
  # @param [Integer] r_index The row index, 0 based.
87
89
  # @param [String] str The string this rows xml will be appended to.
88
90
  # @return [String]
89
- def to_xml_string(r_index, str = '')
90
- serialized_tag('row', str, :r => r_index + 1) do
91
- tmp = '' # time / memory tradeoff, lots of calls to rubyzip costs more
92
- # time..
93
- each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, tmp) }
94
- str << tmp
91
+ def to_xml_string(r_index, str = +'')
92
+ serialized_tag('row', str, r: Axlsx.row_ref(r_index)) do
93
+ each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, str) }
95
94
  end
96
95
  end
97
96
 
@@ -104,29 +103,38 @@ module Axlsx
104
103
  c
105
104
  end
106
105
 
107
- # sets the color for every cell in this row
106
+ # Sets the color for every cell in this row.
108
107
  def color=(color)
109
- each_with_index do | cell, index |
108
+ each_with_index do |cell, index|
110
109
  cell.color = color.is_a?(Array) ? color[index] : color
111
110
  end
112
111
  end
113
112
 
114
- # sets the style for every cell in this row
113
+ # Sets the style for every cell in this row.
115
114
  def style=(style)
116
- each_with_index do | cell, index |
115
+ each_with_index do |cell, index|
117
116
  cell.style = style.is_a?(Array) ? style[index] : style
118
117
  end
119
118
  end
120
119
 
120
+ # Sets escape_formulas for every cell in this row. This determines whether to treat
121
+ # values starting with an equals sign as formulas or as literal strings.
122
+ # @param [Array, Boolean] value The value to set.
123
+ def escape_formulas=(value)
124
+ each_with_index do |cell, index|
125
+ cell.escape_formulas = value.is_a?(Array) ? value[index] : value
126
+ end
127
+ end
128
+
121
129
  # @see height
122
130
  def height=(v)
123
131
  unless v.nil?
124
- Axlsx::validate_unsigned_numeric(v)
132
+ Axlsx.validate_unsigned_numeric(v)
125
133
  @custom_height = true
126
134
  @ht = v
127
135
  end
128
136
  end
129
-
137
+
130
138
  # return cells
131
139
  def cells
132
140
  self
@@ -135,7 +143,10 @@ module Axlsx
135
143
  private
136
144
 
137
145
  # assigns the owning worksheet for this row
138
- def worksheet=(v) DataTypeValidator.validate :row_worksheet, Worksheet, v; @worksheet=v; end
146
+ def worksheet=(v)
147
+ DataTypeValidator.validate :row_worksheet, Worksheet, v
148
+ @worksheet = v
149
+ end
139
150
 
140
151
  # Converts values, types, and style options into cells and associates them with this row.
141
152
  # A new cell is created for each item in the values array.
@@ -146,19 +157,19 @@ module Axlsx
146
157
  # @option options [Array] values
147
158
  # @option options [Array, Symbol] types
148
159
  # @option options [Array, Integer] style
149
- def array_to_cells(values, options={})
160
+ # @option options [Array, Boolean] escape_formulas
161
+ def array_to_cells(values, options = {})
150
162
  DataTypeValidator.validate :array_to_cells, Array, values
151
163
  types, style, formula_values, escape_formulas, offset = options.delete(:types), options.delete(:style), options.delete(:formula_values), options.delete(:escape_formulas), options.delete(:offset)
152
164
  offset.to_i.times { |index| self[index] = Cell.new(self) } if offset
153
165
  values.each_with_index do |value, index|
154
- options[:style] = style.is_a?(Array) ? style[index] : style if style
166
+ options[:style] = (style.is_a?(Array) ? style[index] : style) || worksheet.column_info[index]&.style
155
167
  options[:type] = types.is_a?(Array) ? types[index] : types if types
156
- options[:escape_formulas] = escape_formulas.is_a?(Array) ? escape_formulas[index] : escape_formulas if escape_formulas
168
+ options[:escape_formulas] = escape_formulas.is_a?(Array) ? escape_formulas[index] : escape_formulas unless escape_formulas.nil?
157
169
  options[:formula_value] = formula_values[index] if formula_values.is_a?(Array)
158
170
 
159
171
  self[index + offset.to_i] = Cell.new(self, value, options)
160
172
  end
161
173
  end
162
174
  end
163
-
164
175
  end
@@ -1,11 +1,11 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # A collection of break objects that define row breaks (page breaks) for printing and preview
4
5
 
5
6
  class RowBreaks < SimpleTypedList
6
-
7
7
  def initialize
8
- super Break
8
+ super(Break)
9
9
  end
10
10
 
11
11
  # Adds a row break
@@ -13,19 +13,20 @@ module Axlsx
13
13
  # max and man values are fixed.
14
14
  # @see Break
15
15
  def add_break(options)
16
- # force feed the excel default
17
- self << Break.new(options.merge(:max => 16383, :man => true))
16
+ # force feed the Excel default
17
+ self << Break.new(options.merge(max: 16383, man: true))
18
18
  last
19
19
  end
20
-
20
+
21
21
  # <rowBreaks count="3" manualBreakCount="3">
22
22
  # <brk id="1" max="16383" man="1"/>
23
23
  # <brk id="7" max="16383" man="1"/>
24
24
  # <brk id="13" max="16383" man="1"/>
25
25
  # </rowBreaks>
26
- def to_xml_string(str='')
26
+ def to_xml_string(str = +'')
27
27
  return if empty?
28
- str << ('<rowBreaks count="' << self.size.to_s << '" manualBreakCount="' << self.size.to_s << '">')
28
+
29
+ str << '<rowBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">'
29
30
  each { |brk| brk.to_xml_string(str) }
30
31
  str << '</rowBreaks>'
31
32
  end
@@ -1,11 +1,11 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # Selection options for worksheet panes.
4
5
  #
5
6
  # @note The recommended way to manage the selection pane options is via SheetView#add_selection
6
7
  # @see SheetView#add_selection
7
8
  class Selection
8
-
9
9
  include Axlsx::OptionsParser
10
10
  include Axlsx::SerializedAttributes
11
11
 
@@ -14,7 +14,7 @@ module Axlsx
14
14
  # @option options [Integer] active_cell_id Active Cell Index
15
15
  # @option options [Symbol] pane Pane
16
16
  # @option options [String] sqref Sequence of References
17
- def initialize(options={})
17
+ def initialize(options = {})
18
18
  @active_cell = @active_cell_id = @pane = @sqref = nil
19
19
  parse_options options
20
20
  end
@@ -40,16 +40,16 @@ module Axlsx
40
40
 
41
41
  # Pane
42
42
  # The pane to which this selection belongs.
43
- # Options are
43
+ # Options are
44
44
  # * bottom_left: Bottom left pane, when both vertical and horizontal
45
45
  # splits are applied. This value is also used when only
46
- # a horizontal split has been applied, dividing the pane
47
- # into upper and lower regions. In that case, this value
46
+ # a horizontal split has been applied, dividing the pane
47
+ # into upper and lower regions. In that case, this value
48
48
  # specifies the bottom pane.
49
49
  # * bottom_right: Bottom right pane, when both vertical and horizontal
50
50
  # splits are applied.
51
51
  # * top_left: Top left pane, when both vertical and horizontal splits
52
- # are applied. This value is also used when only a horizontal
52
+ # are applied. This value is also used when only a horizontal
53
53
  # split has been applied, dividing the pane into upper and lower
54
54
  # regions. In that case, this value specifies the top pane.
55
55
  # This value is also used when only a vertical split has
@@ -57,8 +57,8 @@ module Axlsx
57
57
  # regions. In that case, this value specifies the left pane
58
58
  # * top_right: Top right pane, when both vertical and horizontal
59
59
  # splits are applied. This value is also used when only
60
- # a vertical split has been applied, dividing the pane
61
- # into right and left regions. In that case, this value
60
+ # a vertical split has been applied, dividing the pane
61
+ # into right and left regions. In that case, this value
62
62
  # specifies the right pane.
63
63
  # @see type
64
64
  # @return [Symbol]
@@ -74,27 +74,33 @@ module Axlsx
74
74
 
75
75
  # @see active_cell
76
76
  def active_cell=(v)
77
- cell = (v.class == Axlsx::Cell ? v.r_abs : v)
78
- Axlsx::validate_string(cell)
77
+ cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
78
+ Axlsx.validate_string(cell)
79
79
  @active_cell = cell
80
80
  end
81
81
 
82
82
  # @see active_cell_id
83
- def active_cell_id=(v); Axlsx::validate_unsigned_int(v); @active_cell_id = v end
83
+ def active_cell_id=(v)
84
+ Axlsx.validate_unsigned_int(v)
85
+ @active_cell_id = v
86
+ end
84
87
 
85
88
  # @see pane
86
89
  def pane=(v)
87
- Axlsx::validate_pane_type(v)
88
- @pane = Axlsx::camel(v, false)
90
+ Axlsx.validate_pane_type(v)
91
+ @pane = Axlsx.camel(v, false)
89
92
  end
90
93
 
91
94
  # @see sqref
92
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
95
+ def sqref=(v)
96
+ Axlsx.validate_string(v)
97
+ @sqref = v
98
+ end
93
99
 
94
100
  # Serializes the data validation
95
101
  # @param [String] str
96
102
  # @return [String]
97
- def to_xml_string(str = '')
103
+ def to_xml_string(str = +'')
98
104
  serialized_tag 'selection', str
99
105
  end
100
106
  end
@@ -1,15 +1,17 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # the SheetCalcPr object for the worksheet
4
5
  # This object contains calculation properties for the worksheet.
5
6
  class SheetCalcPr
6
- include Axlsx::OptionsParser
7
- include Axlsx::SerializedAttributes
8
- include Axlsx::Accessors
7
+ include Axlsx::OptionsParser
8
+ include Axlsx::SerializedAttributes
9
+ include Axlsx::Accessors
10
+
9
11
  # creates a new SheetCalcPr
10
12
  # @param [Hash] options Options for this object
11
13
  # @option [Boolean] full_calc_on_load @see full_calc_on_load
12
- def initialize(options={})
14
+ def initialize(options = {})
13
15
  @full_calc_on_load = true
14
16
  parse_options options
15
17
  end
@@ -22,8 +24,10 @@ module Axlsx
22
24
  # @param [String] str the string to append this objects serialized
23
25
  # content to.
24
26
  # @return [String]
25
- def to_xml_string(str='')
26
- str << "<sheetCalcPr #{serialized_attributes}/>"
27
+ def to_xml_string(str = +'')
28
+ str << '<sheetCalcPr '
29
+ serialized_attributes(str)
30
+ str << '/>'
27
31
  end
28
32
  end
29
33
  end
@@ -1,27 +1,27 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # This class manages the serialization of rows for worksheets
4
5
  class SheetData
5
-
6
6
  # Creates a new SheetData object
7
7
  # @param [Worksheet] worksheet The worksheet that owns this sheet data.
8
8
  def initialize(worksheet)
9
9
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
10
+
10
11
  @worksheet = worksheet
11
12
  end
12
-
13
+
13
14
  attr_reader :worksheet
14
15
 
15
16
  # Serialize the sheet data
16
17
  # @param [String] str the string this objects serializaton will be concacted to.
17
18
  # @return [String]
18
- def to_xml_string(str = '')
19
+ def to_xml_string(str = +'')
19
20
  str << '<sheetData>'
20
- worksheet.rows.each_with_index do |row, index|
21
- row.to_xml_string(index, str)
21
+ worksheet.rows.each_with_index do |row, index|
22
+ row.to_xml_string(index, str)
22
23
  end
23
24
  str << '</sheetData>'
24
25
  end
25
-
26
26
  end
27
27
  end
@@ -1,17 +1,18 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
- #Sheet formatting properties
4
- # <xsd:complexType name="CT_SheetFormatPr">
5
- # <xsd:attribute name="baseColWidth" type="xsd:unsignedInt" use="optional" default="8"/>
6
- # <xsd:attribute name="defaultColWidth" type="xsd:double" use="optional"/>
7
- # <xsd:attribute name="defaultRowHeight" type="xsd:double" use="required"/>
8
- # <xsd:attribute name="customHeight" type="xsd:boolean" use="optional" default="false"/>
9
- # <xsd:attribute name="zeroHeight" type="xsd:boolean" use="optional" default="false"/>
10
- # <xsd:attribute name="thickTop" type="xsd:boolean" use="optional" default="false"/>
11
- # <xsd:attribute name="thickBottom" type="xsd:boolean" use="optional" default="false"/>
12
- # <xsd:attribute name="outlineLevelRow" type="xsd:unsignedByte" use="optional" default="0"/>
13
- # <xsd:attribute name="outlineLevelCol" type="xsd:unsignedByte" use="optional" default="0"/>
14
- #</xsd:complexType>
3
+ module Axlsx
4
+ # Sheet formatting properties
5
+ # <xsd:complexType name="CT_SheetFormatPr">
6
+ # <xsd:attribute name="baseColWidth" type="xsd:unsignedInt" use="optional" default="8"/>
7
+ # <xsd:attribute name="defaultColWidth" type="xsd:double" use="optional"/>
8
+ # <xsd:attribute name="defaultRowHeight" type="xsd:double" use="required"/>
9
+ # <xsd:attribute name="customHeight" type="xsd:boolean" use="optional" default="false"/>
10
+ # <xsd:attribute name="zeroHeight" type="xsd:boolean" use="optional" default="false"/>
11
+ # <xsd:attribute name="thickTop" type="xsd:boolean" use="optional" default="false"/>
12
+ # <xsd:attribute name="thickBottom" type="xsd:boolean" use="optional" default="false"/>
13
+ # <xsd:attribute name="outlineLevelRow" type="xsd:unsignedByte" use="optional" default="0"/>
14
+ # <xsd:attribute name="outlineLevelCol" type="xsd:unsignedByte" use="optional" default="0"/>
15
+ # </xsd:complexType>
15
16
 
16
17
  class SheetFormatPr
17
18
  include Axlsx::SerializedAttributes
@@ -29,29 +30,32 @@ module Axlsx
29
30
  # @option [Boolean] thick_bottom 'True' if rows have a thick bottom border by default.
30
31
  # @option [Integer] outline_level_row Highest number of outline level for rows in this sheet. These values shall be in synch with the actual sheet outline levels.
31
32
  # @option [Integer] outline_level_col Highest number of outline levels for columns in this sheet. These values shall be in synch with the actual sheet outline levels.
32
- def initialize(options={})
33
+ def initialize(options = {})
33
34
  set_defaults
34
35
  parse_options options
35
36
  end
36
37
 
37
38
  serializable_attributes :base_col_width, :default_col_width, :default_row_height,
38
- :custom_height, :zero_height, :thick_top, :thick_bottom,
39
- :outline_level_row, :outline_level_col
39
+ :custom_height, :zero_height, :thick_top, :thick_bottom,
40
+ :outline_level_row, :outline_level_col
40
41
 
41
42
  float_attr_accessor :default_col_width, :default_row_height
42
43
 
43
44
  boolean_attr_accessor :custom_height, :zero_height, :thick_top, :thick_bottom
44
45
 
45
- unsigned_int_attr_accessor :base_col_width, :outline_level_row, :outline_level_col
46
+ unsigned_int_attr_accessor :base_col_width, :outline_level_row, :outline_level_col
46
47
 
47
48
  # serializes this object to an xml string
48
49
  # @param [String] str The string this objects serialization will be appended to
49
50
  # @return [String]
50
- def to_xml_string(str='')
51
- str << "<sheetFormatPr #{serialized_attributes}/>"
51
+ def to_xml_string(str = +'')
52
+ str << '<sheetFormatPr '
53
+ serialized_attributes(str)
54
+ str << '/>'
52
55
  end
53
56
 
54
57
  private
58
+
55
59
  def set_defaults
56
60
  @base_col_width = 8
57
61
  @default_row_height = 18